Re: Problem executing a .bat script in a directory with spaces using bash

2004-09-07 Thread Brian Dessent
Christopher Cobb wrote:

> Conclusion: cmd.exe command line processing is brain dead.
> 
> Among the problems are that cmd.exe looks for /exactly/ one pair of quotes and
> no more (see my previous message).  And that (double) quotes are the /only/ way
> of quoting spaces.

Wow.  Hideous.

I wonder if there would be any demand for a small compiled wrapper
program that understands cygwin mounts and posix paths, but is a win32
app and calls the win32 or nt api directly to avoid all the quoting
ridiculousless.  It would Just Do What I Mean(tm) when called from
either cygwin or cmd, and be able to launch bat files, cmd files, any
other script-file associations known to Windows, with shebang support as
well.

Am I missing something?  Is this really the next level? Should this be
that hard? It seems like doing it with crafty application of bourne
shell scripting is so painful, and still relies on cmd.exe.

Maybe it could be a feature of the 'run' command, so that it also has
the ability to launch programs without a console / in a new session /
whatever it's called.

Brian

--
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/



Re: Problem executing a .bat script in a directory with spaces using bash

2004-09-07 Thread Christopher Cobb
Christopher Cobb  email.com> writes:

> 
> Brian Dessent  dessent.net> writes:
> >
> > Interesting function.  However, I found that it chokes if the name of
> > the command to run has spaces, even if they are properly quoted on the
> > command line, e.g.
> > 
> 
> That's interesting.  I'm running Win XP and even with your patches I /still/
> get an error when a batch file path with spaces is given.  
>

What I see is that this problem exists even from a cmd.exe window:

This works as expected:

  C:\>type "C:\Documents and Settings\test.bat"
  echo %1

  C:\>"C:\Documents and Settings\test.bat" "Hello, world."
  "Hello, world."

However, this does not work:

  C:\>cmd /c "C:\Documents and Settings\test.bat" "Hello, world."
  'C:\Documents' is not recognized as an internal or external command,
  operable program or batch file.

The problem seems to be the /two/ sets of quotes.  Removing the quotes around
"Hello, world." results in:

  C:\>cmd /c "C:\Documents and Settings\test.bat" Hello, world.

  C:\>echo Hello
  Hello

This gets us to the batch file, but it loses the second argument.  Just for the
record, this is the same (but undesired) behavior invoking the batch file
directly but without quotes on the arguments:

  C:\>"C:\Documents and Settings\test.bat" Hello, world.

  C:\>echo Hello
  Hello

Conclusion: cmd.exe command line processing is brain dead.  

Among the problems are that cmd.exe looks for /exactly/ one pair of quotes and
no more (see my previous message).  And that (double) quotes are the /only/ way
of quoting spaces.




--
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/



Re: Problem executing a .bat script in a directory with spaces using bash

2004-09-07 Thread Christopher Cobb
Brian Dessent  dessent.net> writes:
>
> Interesting function.  However, I found that it chokes if the name of
> the command to run has spaces, even if they are properly quoted on the
> command line, e.g.
> 

That's interesting.  I'm running Win XP and even with your patches I /still/ get
an error when a batch file path with spaces is given.  Shell quoting hell +
cmd.exe quoting hell is enough fun for a whole week!  

As if that's not enough, I see that (at least on XP) cmd.exe has a /S option to
process quotes the "old way":  "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."  

The "new way" is to preserve (exactly two) quotes in the command string if /all/
of the following five conditions are met:  "(1) no /S switch; (2) exactly two
quote characters; (3) no special characters between the two quote characters,
where special is one of: &<>()@^|; (4) there are one or more whitespace
characters between the the two quote characters; (5) the string between the two
quote characters is the name of an executable file."  

I really like it that there /cannot/ be special characters between the quotes,
and that there /must/ be whitespace characters between the quotes.  (NOT!) I
wonder if "executable file" includes batch files?

I'll plug away at this some more and see if I can figure something out.



--
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/



Re: Problem executing a .bat script in a directory with spaces using bash

2004-09-04 Thread Brian Dessent
Christopher Cobb wrote:

> I use the following shell function cmd() to invoke batch files.  It removes
> cygwinisms from the PATH and the environment first and does some argument
> pre-processing.  It also seems to fix the space problem.

Interesting function.  However, I found that it chokes if the name of
the command to run has spaces, even if they are properly quoted on the
command line, e.g.

$ cmd /cygdrive/c/Program\ Files/something\ with\ a\ space/test.bat
'c:Program' is not recognized as an internal or external command,
operable program or batch file.

If you enable "set -x" and run it you see that it's ultimately trying to
execute:

eval /winxp/system32/cmd.exe /c 'c:\Program Files\something with a
space\test.bat'

...which then acutally tries to run:

/winxp/system32/cmd.exe /c c:Program Filessomething with a spacetest.bat

I'm not sure why 'eval' is needed here at all but I assume there's a
good reason.  I'm no scripting guru and the levels of quoting here are
really nasty.  However, I found the following version seems to fix the
issue for me.  It does explicit quoting on the $c part so that the eval
line gets $c with shell-quoting already applied, which it then removes.

cmd ()
{
( local c=`cygpath -w "$1"|sed -r 's@([^a-z0-9.:])@[EMAIL PROTECTED]'`;
shift;
local cmd=`cygpath -u $COMSPEC`;
while [ $# != 0 ]; do
if [ -f "$1" ]; then
local args="$args '`cygpath -w $1`'";
else
if [ -d "$1" ]; then
local args="$args '`cygpath -w $1 | sed '[EMAIL PROTECTED]@@'`'";
else
local args="$args '$1'";
fi;
fi;
shift;
done;
PATH=`echo $PATH |
  tr : '\n' |
  egrep -vw '^(/usr/local/bin|/usr/bin|/bin|/usr/X11R6/bin)$' |
  tr '\n' :`;
unset BASH_ENV COLORTERM CYGWIN DISPLAY HISTCONTROL MAKE_MODE;
unset MANPATH PKG_CONFIG_PATH PS1 PWD SHLVL TERM USER _;
unset CVS CVSROOT CVS_RSH GEN_HOME GROOVY_HOME TOMCAT_DIR;
eval $cmd /c $c $args )
}

This version successfully allows you to do:

cmd /posix/path/with\ spaces\ in\ it/file.bat

..and have it work correctly.

-

I've used a simiar function for a while in the past, but both it and
this still suffer from one really annoying flaw: if an argument that is
meant to be a filename does not exist, the script will not windows-ize
it.  The context that this comes up is that I would like to be able to
run a windows editor, passing it a posix filespec on the command line of
a file that does not exist:

cmd /cygdrive/c/Program\ Files/UltraEdit/uedit32.exe ~/foo

If ~/foo already exists then this is properly translated into:

/winxp/system32/cmd.exe /c 'c:\Program Files\UltraEdit\uedit32.exe'
'C:\cygwin\home\brian\foo'

However, if ~/foo is a new file that does not exist, then the script
will not convert it into a windows path, and the win32 program gets
really confused.  I guess you could assume all arguments are filenames
and "cygpath -w" them, but I'm sure that ends up breaking yet something
else.  Any ideas?

Brian

--
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/



Re: Problem executing a .bat script in a directory with spaces using bash

2004-09-03 Thread Mark Bohlman
Igor Pechtchanski wrote:
On Fri, 3 Sep 2004, Mark Bohlman wrote:

Igor Pechtchanski wrote:
On Fri, 3 Sep 2004, Mark Bohlman wrote:

Igor Pechtchanski wrote:

On Fri, 3 Sep 2004, Christopher Cobb wrote:

I get different results than you do.  It seems to work as expected:
[EMAIL PROTECTED] /c/Documents and Settings 09:45:46
511$ cat test.bat
echo %1
[EMAIL PROTECTED] /c/Documents and Settings 09:45:48
511$ ./test.bat
C:\Documents and Settings>echo
ECHO is on.
I believe you're missing the point.  Try
../test.bat "hello world"
and you'll get the error.
I've come across this when writing a pure Windows loader for
another program.  The above is actually an idiosyncrasy of the way
spawn() works in Cygwin (and, incidentally, in Windows' own
MSVCRT) -- it calls CreateProcess, which expects all arguments
combined into one command string (which, in turn, is later parsed
for separate arguments - yes, retarded, I know).  The fact is
that, if any argument contains spaces, it has to be quoted before
CreateProcess() is invoked.  Cygwin apparently doesn't do this
properly to the first argument, so the above breaks. See
spawn_guts() in winsup/cygwin/spawn.cc (warning: a 590!-line
function). .
Igor
You get the same "odd evaluation behavior" when doing
echo "Hello World" | ./test.bat
(in any directory).
-- Mark
Actually, I don't.  Did you, by chance, mean "echo ...|xargs ./test.bat"?
Even so, you should probably be a bit more specific about the "odd
evaluation behavior" that you're observing.
Igor
Hmmm.  I'm seeing the same results as you show above with a quoted "Hello
World" parameter to the ./test.bat.
Then in doing the echo, without the xargs, results in the same
"non-evaluation" (what i consider to be 'odd') for parameter %1 within the
test.bat file.
-- Mark

Well, piping the output of echo to test.bat's stdin is *not* the same as
passing the string as a parameter.  In the former case, test.bat is called
with no arguments, so %1 evaluates to nothing.  IOW, the behavior you're
seeing is expected.
Igor
Of course you are right on the stdin side.  My mistake.
And I think it's time i move back to Unix systems exclusively as the 
behavior is "as expected" (used loosely) under cmd.exe.
-- Mark

--
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/


Re: Problem executing a .bat script in a directory with spaces using bash

2004-09-03 Thread Igor Pechtchanski
On Fri, 3 Sep 2004, Mark Bohlman wrote:

> Igor Pechtchanski wrote:
> > On Fri, 3 Sep 2004, Mark Bohlman wrote:
> >
> > > Igor Pechtchanski wrote:
> > >
> > > > On Fri, 3 Sep 2004, Christopher Cobb wrote:
> > > >
> > > > > I get different results than you do.  It seems to work as expected:
> > > > >
> > > > > [EMAIL PROTECTED] /c/Documents and Settings 09:45:46
> > > > > 511$ cat test.bat
> > > > > echo %1
> > > > >
> > > > > [EMAIL PROTECTED] /c/Documents and Settings 09:45:48
> > > > > 511$ ./test.bat
> > > > >
> > > > > C:\Documents and Settings>echo
> > > > > ECHO is on.
> > > >
> > > > I believe you're missing the point.  Try
> > > >
> > > > ../test.bat "hello world"
> > > >
> > > > and you'll get the error.
> > > >
> > > > I've come across this when writing a pure Windows loader for
> > > > another program.  The above is actually an idiosyncrasy of the way
> > > > spawn() works in Cygwin (and, incidentally, in Windows' own
> > > > MSVCRT) -- it calls CreateProcess, which expects all arguments
> > > > combined into one command string (which, in turn, is later parsed
> > > > for separate arguments - yes, retarded, I know).  The fact is
> > > > that, if any argument contains spaces, it has to be quoted before
> > > > CreateProcess() is invoked.  Cygwin apparently doesn't do this
> > > > properly to the first argument, so the above breaks. See
> > > > spawn_guts() in winsup/cygwin/spawn.cc (warning: a 590!-line
> > > > function). .
> > > > Igor
> > >
> > > You get the same "odd evaluation behavior" when doing
> > > echo "Hello World" | ./test.bat
> > > (in any directory).
> > > -- Mark
> >
> > Actually, I don't.  Did you, by chance, mean "echo ...|xargs ./test.bat"?
> > Even so, you should probably be a bit more specific about the "odd
> > evaluation behavior" that you're observing.
> > Igor
>
> Hmmm.  I'm seeing the same results as you show above with a quoted "Hello
> World" parameter to the ./test.bat.
>
> Then in doing the echo, without the xargs, results in the same
> "non-evaluation" (what i consider to be 'odd') for parameter %1 within the
> test.bat file.
> -- Mark

Well, piping the output of echo to test.bat's stdin is *not* the same as
passing the string as a parameter.  In the former case, test.bat is called
with no arguments, so %1 evaluates to nothing.  IOW, the behavior you're
seeing is expected.
Igor
-- 
http://cs.nyu.edu/~pechtcha/
  |\  _,,,---,,_[EMAIL PROTECTED]
ZZZzz /,`.-'`'-.  ;-;;,_[EMAIL PROTECTED]
 |,4-  ) )-,_. ,\ (  `'-'   Igor Pechtchanski, Ph.D.
'---''(_/--'  `-'\_) fL a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!

"Happiness lies in being privileged to work hard for long hours in doing
whatever you think is worth doing."  -- Dr. Jubal Harshaw

--
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/



Re: Problem executing a .bat script in a directory with spaces using bash

2004-09-03 Thread Mark Bohlman
Igor Pechtchanski wrote:
On Fri, 3 Sep 2004, Mark Bohlman wrote:

Igor Pechtchanski wrote:
On Fri, 3 Sep 2004, Christopher Cobb wrote:

I get different results than you do.  It seems to work as expected:
[EMAIL PROTECTED] /c/Documents and Settings 09:45:46
511$ cat test.bat
echo %1
[EMAIL PROTECTED] /c/Documents and Settings 09:45:48
511$ ./test.bat
C:\Documents and Settings>echo
ECHO is on.
I believe you're missing the point.  Try
../test.bat "hello world"
and you'll get the error.
I've come across this when writing a pure Windows loader for another
program.  The above is actually an idiosyncrasy of the way spawn() works
in Cygwin (and, incidentally, in Windows' own MSVCRT) -- it calls
CreateProcess, which expects all arguments combined into one command
string (which, in turn, is later parsed for separate arguments - yes,
retarded, I know).  The fact is that, if any argument contains spaces, it
has to be quoted before CreateProcess() is invoked.  Cygwin apparently
doesn't do this properly to the first argument, so the above breaks.  See
spawn_guts() in winsup/cygwin/spawn.cc (warning: a 590!-line function).
.
Igor
You get the same "odd evaluation behavior" when doing
echo "Hello World" | ./test.bat
(in any directory).
-- Mark

Actually, I don't.  Did you, by chance, mean "echo ...|xargs ./test.bat"?
Even so, you should probably be a bit more specific about the "odd
evaluation behavior" that you're observing.
Igor
Hmmm.  I'm seeing the same results as you show above with a quoted 
"Hello World" parameter to the ./test.bat.

Then in doing the echo, without the xargs, results in the same 
"non-evaluation" (what i consider to be 'odd') for parameter %1 within 
the test.bat file.
-- Mark

--
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/


Re: Problem executing a .bat script in a directory with spaces using bash

2004-09-03 Thread Igor Pechtchanski
On Fri, 3 Sep 2004, Mark Bohlman wrote:

> Igor Pechtchanski wrote:
> > On Fri, 3 Sep 2004, Christopher Cobb wrote:
> >
> > > I get different results than you do.  It seems to work as expected:
> > >
> > > [EMAIL PROTECTED] /c/Documents and Settings 09:45:46
> > > 511$ cat test.bat
> > > echo %1
> > >
> > > [EMAIL PROTECTED] /c/Documents and Settings 09:45:48
> > > 511$ ./test.bat
> > >
> > > C:\Documents and Settings>echo
> > > ECHO is on.
> >
> > I believe you're missing the point.  Try
> >
> > ../test.bat "hello world"
> >
> > and you'll get the error.
> >
> > I've come across this when writing a pure Windows loader for another
> > program.  The above is actually an idiosyncrasy of the way spawn() works
> > in Cygwin (and, incidentally, in Windows' own MSVCRT) -- it calls
> > CreateProcess, which expects all arguments combined into one command
> > string (which, in turn, is later parsed for separate arguments - yes,
> > retarded, I know).  The fact is that, if any argument contains spaces, it
> > has to be quoted before CreateProcess() is invoked.  Cygwin apparently
> > doesn't do this properly to the first argument, so the above breaks.  See
> > spawn_guts() in winsup/cygwin/spawn.cc (warning: a 590!-line function).
> > .
> > Igor
>
> You get the same "odd evaluation behavior" when doing
> echo "Hello World" | ./test.bat
> (in any directory).
> -- Mark

Actually, I don't.  Did you, by chance, mean "echo ...|xargs ./test.bat"?
Even so, you should probably be a bit more specific about the "odd
evaluation behavior" that you're observing.
Igor
-- 
http://cs.nyu.edu/~pechtcha/
  |\  _,,,---,,_[EMAIL PROTECTED]
ZZZzz /,`.-'`'-.  ;-;;,_[EMAIL PROTECTED]
 |,4-  ) )-,_. ,\ (  `'-'   Igor Pechtchanski, Ph.D.
'---''(_/--'  `-'\_) fL a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!

"Happiness lies in being privileged to work hard for long hours in doing
whatever you think is worth doing."  -- Dr. Jubal Harshaw

--
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/



Re: Problem executing a .bat script in a directory with spaces using bash

2004-09-03 Thread Christopher Cobb
Igor Pechtchanski  cs.nyu.edu> writes:
> I believe you're missing the point.  Try
> 
> ./test.bat "hello world"
> 
> and you'll get the error.

I use the following shell function cmd() to invoke batch files.  It removes
cygwinisms from the PATH and the environment first and does some argument
pre-processing.  It also seems to fix the space problem.

[EMAIL PROTECTED] /c/Documents and Settings 10:36:09
508$ cat test.bat
echo %1

[EMAIL PROTECTED] /c/Documents and Settings 10:38:30
509$ cmd test "Hello, world."

C:\Documents and Settings>echo "Hello, world." 
"Hello, world."


--- cmd() ---
cmd () 
{ 
( local c="`cygpath -w \"$1\"`";
shift;
local cmd=`cygpath -u $COMSPEC`;
while [ $# != 0 ]; do
if [ -f "$1" ]; then
local args="$args '`cygpath -w $1`'";
else
if [ -d "$1" ]; then
local args="$args '`cygpath -w $1 | sed '[EMAIL PROTECTED]@@'`'";
else
local args="$args '$1'";
fi;
fi;
shift;
done;
PATH=`echo $PATH |
  tr : '\n' |
  egrep -vw '^(/usr/local/bin|/usr/bin|/bin|/usr/X11R6/bin)$' |
  tr '\n' :`;
unset BASH_ENV COLORTERM CYGWIN DISPLAY HISTCONTROL MAKE_MODE;
unset MANPATH PKG_CONFIG_PATH PS1 PWD SHLVL TERM USER _;
unset CVS CVSROOT CVS_RSH GEN_HOME GROOVY_HOME TOMCAT_DIR;
eval $cmd /c "$c" $args )
}
--- end cmd() ---



--
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/



Re: Problem executing a .bat script in a directory with spaces using bash

2004-09-03 Thread Mark Bohlman
Igor Pechtchanski wrote:
On Fri, 3 Sep 2004, Christopher Cobb wrote:

I get different results than you do.  It seems to work as expected:
[EMAIL PROTECTED] /c/Documents and Settings 09:45:46
511$ cat test.bat
echo %1
[EMAIL PROTECTED] /c/Documents and Settings 09:45:48
511$ ./test.bat
C:\Documents and Settings>echo
ECHO is on.

I believe you're missing the point.  Try
../test.bat "hello world"
and you'll get the error.
I've come across this when writing a pure Windows loader for another
program.  The above is actually an idiosyncrasy of the way spawn() works
in Cygwin (and, incidentally, in Windows' own MSVCRT) -- it calls
CreateProcess, which expects all arguments combined into one command
string (which, in turn, is later parsed for separate arguments - yes,
retarded, I know).  The fact is that, if any argument contains spaces, it
has to be quoted before CreateProcess() is invoked.  Cygwin apparently
doesn't do this properly to the first argument, so the above breaks.  See
spawn_guts() in winsup/cygwin/spawn.cc (warning: a 590!-line function).
.
Igor

You get the same "odd evaluation behavior" when doing
echo "Hello World" | ./test.bat
(in any directory).
-- Mark
--
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/


Re: Problem executing a .bat script in a directory with spaces using bash

2004-09-03 Thread Igor Pechtchanski
On Fri, 3 Sep 2004, Christopher Cobb wrote:

> I get different results than you do.  It seems to work as expected:
>
> [EMAIL PROTECTED] /c/Documents and Settings 09:45:46
> 511$ cat test.bat
> echo %1
>
> [EMAIL PROTECTED] /c/Documents and Settings 09:45:48
> 511$ ./test.bat
>
> C:\Documents and Settings>echo
> ECHO is on.

I believe you're missing the point.  Try

./test.bat "hello world"

and you'll get the error.

I've come across this when writing a pure Windows loader for another
program.  The above is actually an idiosyncrasy of the way spawn() works
in Cygwin (and, incidentally, in Windows' own MSVCRT) -- it calls
CreateProcess, which expects all arguments combined into one command
string (which, in turn, is later parsed for separate arguments - yes,
retarded, I know).  The fact is that, if any argument contains spaces, it
has to be quoted before CreateProcess() is invoked.  Cygwin apparently
doesn't do this properly to the first argument, so the above breaks.  See
spawn_guts() in winsup/cygwin/spawn.cc (warning: a 590!-line function).
.
Igor
-- 
http://cs.nyu.edu/~pechtcha/
  |\  _,,,---,,_[EMAIL PROTECTED]
ZZZzz /,`.-'`'-.  ;-;;,_[EMAIL PROTECTED]
 |,4-  ) )-,_. ,\ (  `'-'   Igor Pechtchanski, Ph.D.
'---''(_/--'  `-'\_) fL a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!

"Happiness lies in being privileged to work hard for long hours in doing
whatever you think is worth doing."  -- Dr. Jubal Harshaw

--
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/



Re: Problem executing a .bat script in a directory with spaces using bash

2004-09-03 Thread Christopher Cobb
I get different results than you do.  It seems to work as expected:

[EMAIL PROTECTED] /c/Documents and Settings 09:45:46
511$ cat test.bat
echo %1

[EMAIL PROTECTED] /c/Documents and Settings 09:45:48
511$ ./test.bat

C:\Documents and Settings>echo  
ECHO is on.




--
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/



Re: Re: Problem executing a .bat script in a directory with spaces using bash

2004-09-02 Thread Larry Hall
At 02:23 PM 9/2/2004, you wrote:





>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
>
>
>This just doesn't seem right to me.


But it does suggest that the whole process is causing you to loose which
arguments are which.  In this case, your $0 is becoming /cygdrive/c/Space.
So you might try quoting your path to the script instead.  I expect 
strace of the shell could help you see where things "go wrong" if you're 
looking for more insight.


--
Larry Hall  http://www.rfk.com
RFK Partners, Inc.  (508) 893-9779 - RFK Office
838 Washington Street   (508) 893-9889 - FAX
Holliston, MA 01746 


--
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/



Re: Problem executing a .bat script in a directory with spaces using bash

2004-09-02 Thread CyberZombie
I typed too soon...
/c/Documents and Settings>./test.bat "Hello world"
'c:\Documents' is not recognized as an internal or external command,
operable program or batch file.
CyberZombie wrote:
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
Hello
/c/Documents and Settings>ls -l test.bat
-rwxr-xr-x1 Rob  None8 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

./test.bat "hello world"

'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
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

This just doesn't seem right to me.
Sean
On Thu, 02 Sep 2004 11:04:45 -0700, GD <[EMAIL PROTECTED]> wrote:
 

...
I apologize for making that false assumption.
Thanks.
Sean

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:  http://cygwin.com/ml/#unsubscribe-simple
Problem reports:   http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ:   http://cygwin.com/faq/
 


--
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/


--
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/


Re: Problem executing a .bat script in a directory with spaces using bash

2004-09-02 Thread CyberZombie
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
Hello
/c/Documents and Settings>ls -l test.bat
-rwxr-xr-x1 Rob  None8 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

./test.bat "hello world"

'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
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

This just doesn't seem right to me.
Sean
On Thu, 02 Sep 2004 11:04:45 -0700, GD <[EMAIL PROTECTED]> wrote:
 

...
I apologize for making that false assumption.
Thanks.
Sean
 

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:  http://cygwin.com/ml/#unsubscribe-simple
Problem reports:   http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ:   http://cygwin.com/faq/
 


--
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/


Re: Re: Problem executing a .bat script in a directory with spaces using bash

2004-09-02 Thread Sean Daley
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


./test.bat "hello world"

'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
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


This just doesn't seem right to me.

Sean

On Thu, 02 Sep 2004 11:04:45 -0700, GD <[EMAIL PROTECTED]> wrote:
> >...
> >I apologize for making that false assumption.
> >
> >Thanks.
> >
> >Sean
> >
> 
> 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:  http://cygwin.com/ml/#unsubscribe-simple
Problem reports:   http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ:   http://cygwin.com/faq/



Re: Re: Problem executing a .bat script in a directory with spaces using bash

2004-09-02 Thread Sean Daley
Thank you for your most eloquent and considerably rude response.
Though maybe that's my fault for not mentioning in my initial email that
writing a shell script (which is something that I can do) is not an option.

Unfortunately there are reasons why we need these .bat scripts (yes I don't
like that and I wish that I could use scripts since they are much more powerful
and easier to use) but once again I can't.

To give a slightly closer idea of what I'm trying to accomplish:

I have a program that can be used to launch native programs.
This program can be used to execute batch scripts which are associated with
third-party applications.  While testing this program linked against
cygwin, I ran
into the issue documented below.

I then thought I'd try to separate my app from the problem so I tested it using
cygwin's bash and once again ran into the issue documented below.

Now you may not use them (batch scripts) or care about them but I do.

Before I delved into src/winsup/cygwin/spawn.cc I thought I would
email this list
in case someone had something educational to say about the issue.

I apologize for making that false assumption.

Thanks.

Sean

On Thu, 02 Sep 2004 10:20:44 -0700, GD <[EMAIL PROTECTED]> wrote:
> Sean Daley wrote:
> 
> >I'm currently using cygwin 1.5.10 and I'm having a problem trying to
> >run a .bat file in
> >a directory with spaces.
> >
> Geezus, man!  You're not going to get a response from the Cygwin list
> for shell  questions with obvious answers.
> 
> Windows is case insensitive.
> *nix systems are case sensitive.
> 
> Windows performs quoting tricks (that no one really understands) behind
> the scenes.
> *nix systems treats spaces as delimiters
> 
> Windows uses the backslash character to delineate directories
> *nix systems and the rest of the world treat the backslash as an escape
> character
> 
> To solve your immediate problems:
> 
> ---cut here
> #!/usr/bin/bash
> # shell script to echo passed parameter
> # scriptname: sean
> 
> if [ $1 ]
> then
>echo $1
> else
>echo "No one here."
> fi
> ---
> 
> [EMAIL PROTECTED] /cygdrive/c
> $ mkdir a\ directory\ with\ spaces\ in\ the\ name
> 
> [  [EMAIL PROTECTED] /cygdrive/c
>$ mkdir "a directory with spaces in the name"
> 
>[EMAIL PROTECTED] /cygdrive/c
>$ mkdir 'a directory with spaces in the name' ]
> 
> [EMAIL PROTECTED] /cygdrive/c
> cd "a directory with spaces in the name"
> 
> [EMAIL PROTECTED] /cygdrive/c/a directory with spaces in the name
> $ bash sean foobar
> foobar
> 
> And forget the batch files.  No one uses them or wants to hear about
> them.  Write a shell script, write a Perl script, write something more
> sensible.  Cygwin has provided hundreds of tools for your use.
> 
> Now go read any of the hundreds of shell scripting tutorials available
> on the web.
> 
> Cheers.
> 
>

--
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/