Date: Fri, 29 Jun 2001 21:53:10 +0300 From: "Eli Zaretskii" Sender: halo1 AT zahav DOT net DOT il To: Jonathon Merz Message-Id: <6923-Fri29Jun2001215309+0300-eliz@is.elta.co.il> X-Mailer: Emacs 20.6 (via feedmail 8.3.emacs20_6 I) and Blat ver 1.8.9 CC: djgpp AT delorie DOT com In-reply-to: <3B3CADA3.4000506@earthlink.net> (message from Jonathon Merz on Fri, 29 Jun 2001 11:32:35 -0500) Subject: Re: Incorrect resolution of COMSPEC environment variable on WinNT References: <3B3CADA3 DOT 4000506 AT earthlink DOT net> Reply-To: djgpp AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk > Date: Fri, 29 Jun 2001 11:32:35 -0500 > From: Jonathon Merz > > Is this a bug or am I missing something? You are missing something ;-) > main() > { > char *comspec_value = getenv("COMSPEC"); > printf("%s\n", comspec_value); > } > > When compiled with DJGPP's gcc on WinNT 4, the output is: > > C:\WINNT\SYSTEM32\COMMAND.COM > > The trouble is that on NT 4, (and I have verified this in my shell) COMSPEC is > set to c:\winnt\system32\cmd.exe. The correct value is output when compiled > under several other compilers. This is a ``feature'' of Windows NT: when a DOS program runs, it gets COMMAND.COM as the value of COMSPEC in its environment, even if outside the program COMSPEC has a different value. Windows NT doesn't want DOS programs to think they are on Windows, it pretends to be DOS. Likewise, all the names of important (or maybe all, I forget) environment variables are up-cased when they are passed to DOS programs. Thus, Path is converted to PATH, ComSpec is converted to COMSPEC, etc. There's nothing (AFAIK) a DOS program can do to avoid this, because this behavior is entirely inside the NT DOS emulator. However, why is this a problem in your case? DOS programs in general and DJGPP programs in particular should not normally care about this. > if there is a way to identify the operating system the program is > running under It's not easy. For example, there's no easy way we know of to distinguish NT from Windows 2000. But if you don't care about the difference, call _get_dos_version(1), and if it returns the version 5.50, you are on NT.