This is the mail archive of the cygwin@sourceware.cygnus.com 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]

Re: B20.1 sh and bash command line parsing question


--- Rob Tulloh <rob_tulloh@dev.tivoli.com> wrote:
> Hello,

Hi Rob,

> 
> As a maintainer of GNU make on WIN32 platforms, I am constantly asked
> why Cygwin sh.exe and/or bash.exe don't work correctly when called
> from make. I have a hack that forces all shell commands to be written
> to a temp file and then run via 'sh file'. However, I don't like
> this as it represents a unnecessary performance hit to make on WIN32
> platforms. I have a simple test case that shows the problems.
> 

This is one reason I'm not using your native port.  I've successfully built the
native port with MINGW32 and used it only in trying to understand what is going
on with it to try to help someone else.  One thing I changed, if the debug
switch is used to not delete the temporary bat files.  This allowed me to look
at them and execute them by hand to determine problems.

> I am trying to work out why sh.exe and bash.exe are not able to
> be succesfully invoked via 'sh -c' from CreateProcess() for
> all cases of command line. I have
> a simple test example that can be run from the NT command prompt
> which demonstrates the problem. There are 6 lines below which
> use 3 shells to execute 2 different command lines:
> 

What values are set in the CYGWIN environment variable?  Note, if you have tty
set then you're not going to communicate via stdio properly with non-cygwin
programs.

> > i:/apps/work/cygnus/CYGWIN~1/H-I586~1/bin/sh.exe -c "if [ -d \"c:/temp\" ]
> ; then echo \"hi\" ; fi"
> > i:/apps/work/cygnus/CYGWIN~1/H-I586~1/bin/bash.exe -c "if [ -d \"c:/temp\"
> ] ; then echo \"hi\" ; fi"
> > i:/tools/gk/bin/sh.exe -c "if [ -d \"c:/temp\" ] ; then echo \"hi\" ; fi"
> > i:/apps/work/cygnus/CYGWIN~1/H-I586~1/bin/sh.exe -c "if [ -d \"c:/temp\" ]
> ; then echo \"hi there\" ; fi"
> > i:/apps/work/cygnus/CYGWIN~1/H-I586~1/bin/bash.exe -c "if [ -d \"c:/temp\"
> ] ; then echo \"hi there\" ; fi"
> > i:/tools/gk/bin/sh.exe -c "if [ -d \"c:/temp\" ] ; then echo \"hi there\" ;
> fi"
> 
> The first 2 shells are the ones from the Cygwin B20.1 distribution. The
> 3rd shell is Tivoli's custom port of GNU bash to Windows NT. 
> 

Where can I get the source/binary distribution of Tivoli's custom port?  I'm
interested for self educational purposes.

> > I:\apps\work\cygnus\cygwin-b20>c:\temp\sp2.bat
> > 
> >
>
I:\apps\work\cygnus\cygwin-b20>i:/apps/work/cygnus/CYGWIN~1/H-I586~1/bin/sh.exe
> > -c "if [ -d \"c:/temp\" ] ; then echo \"hi\" ; fi"
> > hi
> > 
> >
>
I:\apps\work\cygnus\cygwin-b20>i:/apps/work/cygnus/CYGWIN~1/H-I586~1/bin/bash.ex
> > e -c "if [ -d \"c:/temp\" ] ; then echo \"hi\" ; fi"
> > hi
> > 
> > I:\apps\work\cygnus\cygwin-b20>i:/tools/gk/bin/sh.exe -c "if [ -d
> \"c:/temp\" ]
> > ; then echo \"hi\" ; fi"
> > hi
> > 
> >
>
I:\apps\work\cygnus\cygwin-b20>i:/apps/work/cygnus/CYGWIN~1/H-I586~1/bin/sh.exe
> > -c "if [ -d \"c:/temp\" ] ; then echo \"hi there\" ; fi"
> > Syntax error: Unterminated quoted string
> > 
> >
>
I:\apps\work\cygnus\cygwin-b20>i:/apps/work/cygnus/CYGWIN~1/H-I586~1/bin/bash.ex
> > e -c "if [ -d \"c:/temp\" ] ; then echo \"hi there\" ; fi"
> > there\ ; fi: -c: line 1: unexpected EOF while looking for matching `"'
> > there\ ; fi: -c: line 2: syntax error: unexpected end of file
> > 
> > I:\apps\work\cygnus\cygwin-b20>i:/tools/gk/bin/sh.exe -c "if [ -d
> \"c:/temp\" ]
> > ; then echo \"hi there\" ; fi"
> > hi there
> 
> 
> Notice how as soon as white space ("hi there") is introduced into a

One of the most common problems for the case of passing arguments from one
runtime to the other is the quoting of strings.  One user recently noted that
using the single quote instead of the double quote helped the issue of
communicating quotes between cygwin and non-cygwin programs.


> string
> embedded in the command line that 
> the parser breaks down and fails to parse the string correctly. I would
> have thought that the parsing rules would follow the Microsoft C runtime
> rules for argument parsing since it should be possible to invoke Cygwin
> commands from CreateProcess() (natively from Win32) rather than having
> to rely on fork/exec/whatever in cygwin.dll.
> 
> Note that I have made the parsing logic within make work for Tivoli's
> custom
> port of bash and also for the MKS version of sh. I am not able to figure
> out what magic is needed to make this work with Cygwin sh or bash. I am
> looking
> for insight on what the parsing algorithm is and how to invoke commands
> from
> WIN32 so that sh/bash can parse them as I would expect. 
> 
> Comments?
> 

You should try more recent snapshots as well.  If you do, add a nontsec to the
CYGWIN variable, this is a new feature that isn't completely debugged and has
caused no end of problems, at least for me, and turning it of I've had no
problems with recent snapshots.


> Thank you,
> 

You're welcome,

===
Earnie Boyd <mailto:earnie_boyd@yahoo.com>

Newbies, please visit
<http://www.freeyellow.com/members5/gw32/index.html>

(If you respond to the list, then please don't cc me)
__________________________________________________
Do You Yahoo!?
Bid and sell for free at http://auctions.yahoo.com


--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com


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