[Python-bugs-list] "Fix" os.system() on Windows (PR#406)

Tim Peters tim_one@email.msn.com
Sun, 23 Jul 2000 01:06:45 -0400


[Mark Hammond]
> I'm afraid there is a backwards compatibility issue here.  Existing
> code that uses a command.com builtin command will break.

Indeed, Tcl contains thousands of lines of miserable Win-specific code
trying to make their version of "system" work correctly.  It's A Project!

> ...
> Interestingly, this bug in Windows appears to be fixed in
> Windows 2000.

IIRC, the correct exit code comes back in NT too -- a command.com vs cmd.exe
thing (command.com *always* returns a 0 exit code).  MS's "system" does
return the exit code of the thing it spawns, so it's the command shell that
screws us, not Python's or MS's implementation of "system".  The easiest fix
is to buy a "real shell" and set COMSPEC to point to it (the MS system uses
COMSPEC to figure out which shell to spawn).  Here on Win98:

C:\tmp>type testit.cpp
int
main()
{
    return 32;
}

C:\tmp>cl testit.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8168 for 80x86
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.

testit.cpp
Microsoft (R) Incremental Linker Version 6.00.8447
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

/out:testit.exe
testit.obj

C:\tmp>set COMSPEC=\tmp\testit.exe

C:\tmp>\python16\python
Python 1.6a2 (#0, Apr  6 2000, 11:45:12) [MSC 32 bit (Intel)] on win32
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import os
>>> os.system("blah")
32
>>>

That shows Win98 does indeed return the exit code of the shell that gets
spawned -- this is a command.com bug.  In the absence of a shell that works
correctly, not much Python can do about it.