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: Problem executing a .bat script in a directory with spaces using bash

I don't get that behavior...

~>cd /c/Documents\ and\ Settings
/c/Documents and Settings>cat test.bat
@echo %1
/c/Documents and Settings>./test.bat Hello world
/c/Documents and Settings>ls -l test.bat
-rwxr-xr-x    1 Rob      None            8 Sep  2 13:53 test.bat
/c/Documents and Settings>

Sean Daley wrote:

The problem is, there's nothing for me to quote here.  It's not like
the batch script fails to
give me the correct information (due to incorrect quoting).  The
script fails to even
LAUNCH when it lives in a directory with spaces and you pass in an argument with
a space in it.  Mind you, I've changed directory to that directory
with spaces so I'm
not trying to do something like:
"/cygdrive/c/Space \Dir/test.bat" "hello world"

cd /cygdrive/c/Space\ Dir
./test.bat hello
<works just fine>

./test.bat "hello world"
<fails with:>
'c:\Space' is not recognized as an internal or external command,
operable program or batch file.

And all test.bat does is echo %1
change test.bat to do just echo (so it doesn't even process its arguments)
and it still fails accordingly.

Let me just give one final example (this time test.bat says echo %*)

$ /cygdrive/c/Space\ Dir/test.bat hello
c:\Space Dir>echo hello
$ /cygdrive/c/Space\ Dir/test.bat hello world
c:\Space Dir>echo hello world
hello world
$ /cygdrive/c/Space\ Dir/test.bat "hello world"
'c:\Space' is not recognized as an internal or external command,
operable program or batch file.

I'm running the exact same command all three times with different arguments.
The minute I pass a quoted argument (with spaces) to the batch script though,
bash itself complains about not being able to find test.bat.

Now let's take this one step further.  In the last case, it actually
thinks it wants
to execute C:\Space instead of the script.  Now let's do the following:
Create a batch script called "C:\Space.bat" and put one line into it.
cat /etc/passwd.

Now re-run the third command again:
$ /cygdrive/c/Space\ Dir/test.bat "hello world"
c:\Space Dir>cat /etc/passwd
<etc/passwd file is now displayed>

This just doesn't seem right to me.


On Thu, 02 Sep 2004 11:04:45 -0700, GD <> wrote:

I apologize for making that false assumption.



Sorry for sounding rude, but admittedly I was a bit terse. :-)  Your
post raised simple shell quoting issues and nothing else. Honeslty, I'm
not understanding the problem as you're describing it, but if spaces in
a file/directory name is causing an issue, then why wouldn't the simple
use of single quoting (for example) to prevent shell expansion not solve it?

-- Unsubscribe info: Problem reports: Documentation: FAQ:

Unsubscribe info:
Problem reports:

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