Web lists-archives.org

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




Tor Lillqvist wrote:
>>  My console code behaves differently when running in a DOS box
> 
> Please don't say "DOS box" if you actually mean cmd.exe (or some other
> shell) is a console window. (MS-)DOS has nothing to do with it.

Yes, I do mean cmd.exe.

> Well, this is not the Cygwin mailing list. But if your program is not
> a Cygwin program, but a native Win32 one, built using mingw, I guess
> your question isn't off-topic.

Thanks :)

This is a MinGW app, but I've noticed that I need different versions of 
the code because it may run on different shells. It seemed to me that 
MinGW users might have this problem, but Cygwin users probably wouldn't.
Ideally, I need a 'uname' that returns either Windows or Cygwin. I 
suppose there's nothing like this in mingwex?

> Is this Cygwin bash running in rxvt or a console window? That might
> explain the difference in behaviour.

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.

I'm still experimenting and I don't really understand what the problems 
are. However, if I can find out what shell my app was spawned from that 
would certainly help.

You may be thinking that I should just specify 'cmd /c' to 
'CreateProcess', since it shouldn't matter whether the end-user is 
running in a DOS box or some other shell. This may be right, but it's a 
bit more complicated than that. This program is the client half of a 
client-server app, and the remote server will normally be expecting 
Unix-like behaviour on the client. So, at the very least, I need to know 
whether I can support Unix-like behaviour at the client.

Thanks for the code, but I think I'll get "console input" for both cases 
(is that right?)

I can let you have an 'error_message' that handles Winsock errors as 
well, if you haven't already got it and want it.

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