grabbing return codes from os.system() call
Tim Peters
tim.one at home.com
Sun Mar 11 01:12:23 EST 2001
[Gregory Jorgensen]
> Actually the current docs at python.org say that Windows 95 and 98
> always return 0. Apparently Windows NT and 2000 do return something.
> I don't know about Win ME. The Beazley book "Python Essential Reference"
> (which I used) says "On Windows, the exit code is always 0" in the
> description of os.system.
On any Windows box,
Python's os.system() calls Microsoft's system().
Microsoft's system() constructs a command line, and
effective executes
%COMSPEC% /c the_command_line
in a new shell.
The return value of the shell (%COMSPEC%) is returned
by Microsoft's system(), which is in turn returned by
Python's os.system().
My Win98SE box is typical of all Win9X systems:
C:\Code>echo %COMSPEC%
C:\WINDOWS\COMMAND.COM
C:\Code>
While it doesn't appear to be documented anywhere, command.com returns 0 no
matter what happens.
NT/Win2K generally use cmd.exe instead, and that returns the same exit code
as the command line it runs.
There is no way to work around the Win9X behavior except via installing a
different DOS shell and setting %COMSPEC% to point to that.
More information about the Python-list
mailing list