This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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
is
  used to process quote (") characters:

      1.  If all of the following conditions are met, then quote
characters
          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,
preserving
          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 docume~1
and
  c:\>dir "Documents and Settings"

To find out the short names,
  c:\>dir /x
Or one can guess (first 6 characters + "~" + "1", or a higher digit if
the 6 characters + "~1" is already used, + "." + first 3 characters of
the extension).

Try changing the batch file from
  echo %1
to
  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
world"
  exit' | u2d | cmd /k
  c:\>"c:\Documents and Settings\BBuchbinder\test.bat" "hello world"

  c:\>echo "hello world"
  "hello world"

c:\>exit

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. Thank you.


Johnathon

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]