Web lists-archives.org

Re: [Mingw-users] How can I tell whether my prog is running on cmd.exe or bash?




Keith Marshall wrote:

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

It turns out that, in the standard Cygwin setup, bash doesn't export 
SHELL, among various other things. I've gone off this idea, given that 
PATH generally also contains lots of cruft. My current plan Z is (I've 
just posted this on the cygwin list, where Greg suggested uname and did 
some test code):

if(
    (system(uname) looks sane) &&
    (system(cygpath -m /bin/sh) returns success))
      use CreateProcess with /bin/sh path returned by cygpath;
  else
      use CreateProcess with cmd.exe /c

And I'll need to test it when run from a DOS box, with Cygwin's bin in 
the path.

That should keep most of the people happy most of the time. Who can ask 
for more from Windows?  :)

Thanks

-Paul

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