This is the mail archive of the
mailing list for the Cygwin project.
Re: Bash fails to run .bat file with spaces in pathname and argument
Buchbinder, Barry (NIH/NIAID) [E] wrote:
The problem is, at least in part, with cmd. cmd /? says:
If /C or /K is specified, then the remainder of the command line after
the switch is processed as a command line, where the following logic
used to process quote (") characters:
1. If all of the following conditions are met, then quote
on the command line are preserved:
- no /S switch
- exactly two quote characters
- no special characters between the two quote characters,
where special is one of: &<>()@^|
- there are one or more whitespace characters between the
the two quote characters
- the string between the two quote characters is the name
of an executable file.
2. Otherwise, old behavior is to see if the first character is
a quote character and if so, strip the leading character and
remove the last quote character on the command line,
any text after the last quote character.
This tells me that CreateProcess is not really at fault at all, but
instead the fix is to create a different command line. I can think of
one of two things: (1) do not have a double quote as the first
character, (2) if the program is quoted and there exists an argument
quoted as well, replace ' ' with '^ ' everywhere in the program and add
a '^' at the end of the program before the quote.
Try using short names to get rid of the first set of quotes. Short
names still work, at least on XP. Compare
c:\>dir "Documents and Settings"
To find out the short names,
Or one can guess (first 6 characters + "~" + "1", or a higher digit if
the 6 characters + "~1" is already used, + "." + first 3 characters of
Try changing the batch file from
echo %1 %2 %3 %4 %5 %6 %7 %8 %9
That should work by getting rid of the second set of quotes, at least if
the number of arguments is less than 10.
This, also, works
/c> echo '"c:\Documents and Settings\BBuchbinder\test.bat" "hello
exit' | u2d | cmd /k
c:\>"c:\Documents and Settings\BBuchbinder\test.bat" "hello world"
c:\>echo "hello world"
You can leave off the "/k", but you then get extraneous text from
cmd.exe as it loads.
This is a lot of good info, especially since I generally do not use DOS.
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html