Re: [Mingw-users] How can I tell whether my prog is running on cmd.exe or bash?
- Date: Thu, 7 Feb 2008 00:24:36 +0000
- From: Keith Marshall <keithmarshall@xxxxxxxxxxxxxxxxxxxxx>
- Subject: Re: [Mingw-users] How can I tell whether my prog is running on cmd.exe or bash?
On Wednesday 06 February 2008 16:14, Earnie Boyd wrote:
> Quoting Paul Leder <sa212+mingw@xxxxxxxxxxx>:
> > The problem is that I call 'system' and 'CreateProcess' to spawn
> > child processes. These have different requirements for backslashes
> > and quote characters depending on what shell they use. I specify
> > the shell myself for 'CreateProcess' ('cmd /c' or '/bin/bash -c'),
> > but I still need to know which shell to use. I also need to adjust
> > the command line that I give to 'system'. I haven't tried the
> > different ways of running bash. In development, I just use the
> > basic console window; no tty or rxvt.
>
> Check for the environment variable SHELL. If it doesn't exist use
> the value of COMSPEC /c otherwise use the value of SHELL -c.
Or, if you don't have an issue with GPLv2 code, have a look at the exec
wrappers library, in the User Contributed section of the MinGW download
page, on SourceForge:
http://sourceforge.net/project/platformdownload.php?group_id=2435
http://sourceforge.net/project/showfiles.php?group_id=2435&package_id=59819&release_id=112191
This includes a replacement for the system() function, which favours
Unixy shells over cmd.exe, according to the paradigm:--
1) Try any shell specified by the SHELL environment variable.
2) If (1) fails, search the PATH for a suitable shell, and run the
specified command using the first of bash, ksh, pdksh, zsh, ash, sh,
tcsh or csh to be successfully invoked.
3) If all else fails, fall back to the standard MSVCRT system() call,
which will invoke the command using the shell specified by the COMSPEC
environment variable.
In addition to this, the library provides wrappers for the entire family
of spawn and exec functions, which correctly handle argument grouping
and quoting, (the MSVCRT implementations are seriously broken); IMO,
these provide a much nicer, (definitely more Unixy), API for invoking
child processes, than MSVCRT's ghastly CreateProcess().
Regards,
Keith.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
MinGW-users mailing list
MinGW-users@xxxxxxxxxxxxxxxxxxxxx
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users