Web lists-archives.org

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




Quoting Paul Leder <sa212+mingw@xxxxxxxxxxx>:

> Keith Marshall wrote:
>
>>> 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
>>
>> Yuck!!!  That has to do a PATH search anyway, to find first uname, and
>> then cygpath.
>
> That's Ok, I think. I'm expecting the user to have crud in their PATH (I
> do, anyway, going back over an eternity of obsolete apps) but, if
> they're using Cygwin at all, then *that* should be in their PATH. If it
> isn't, then that's their problem; I fall back to cmd.exe.
>

If your program is executed from Cygwin (or MSYS) then yes but on this 
list we encourage PPL to not add these to there windows PATH.

>> Furthermore, it *only* works when the Unixy shell is of
>> the Cygwin variety; what if your user has some other Unixy shell, and
>> would expect that to be used?
>
> I have to confess that I didn't know that there were any other Unixy
> shells on Windows (I haven't looked at MSYS). Besides, I've worked in
> the industry I'm writing this app for for ~20 years, and I've never
> heard of anyone using anything other than Cygwin or plain DOS. The smart
> ones are on Solaris or Linux; the cash-strapped ones are on Cygwin; the
> amateurs are on Windows GUI apps.
>

MSYS is an old version of Cygwin I forked many years ago.  It had a 
simple goal of being able to execute a typical configure && make for 
the mingw target using the mingw tool set.

> Besides, I've got to draw the line somewhere at supporting obscure
> shells. It's hard work. Anything which is even vaguely Unixy must have a
> /bin/sh.
>
> It's true that only Cygwin will have a cygpath, but I can't see how to
> get rid of that. Just parsing PATH is useless to me. I could look for a
> host of shells in all locations in PATH, but (1) if it's a Cygwin PATH
> then it's no use because it won't make sense to 'CreateProcess' until
> it's been through 'cygpath -m' anyway, and (2) the 'shell' may turn out
> to be a completely irrelevant Windows program called, for example, ksh.exe.
>

Now, that's where MSYS comes in handy.  I insisted that cygpath was not 
necessary and MSYS converts the PATH to something useful for a native 
windows app.  The only thing that comes close is a -W switch to the pwd 
command.

> In short, I can't take the risk of executing some arbitrary Windows
> program just because it has the right name and happens to be on the
> path. Either it's /bin/sh, or nothing. Actually, the more I think about
> it, the less sense the exec wrappers stuff makes. Feel free to correct
> me... :)
>

But what does /bin/sh convert to in windows?  You'll come up short 
unless /bin is on the root of the current drive.  How do you determine 
where /bin exists?

Earnie

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