Executing files

Tim Peters tim_one at email.msn.com
Thu Sep 21 00:27:43 CEST 2000

[Mark W Daley, running a customized Python on something "like" DOS]
> ...
> 	- os.system could execute, but the return is whether or not
> Python executed the command, not whether the command completed
> successfully.

Since you've customized Python and aren't actually running DOS, it's risky
to guess, but here goes:

On a non-customized Python running on real DOS, os.system always returns 0
whenever the argument passed to it runs at all.  That's because command.com
ignores the exit status of commands *it* runs, returning 0 as its own exit
status:  Microsoft's implementation of "system" (which Python calls
directly) builds a command line out of %COMSPEC% and the argument to
"system", like so:

    %COMSPEC% /c argument_to_system

then spawns a process to run that (note that the source code for Microsoft's
"system" is available in crt\src\system.c, provided you elected to install
the C runtime source when you installed MSVC).  Since command.com always
returns 0, that's what Microsoft's system returns to Python's os.system
returns to you.

To fix this, you need a better shell, and point the COMSPEC envar at it.
IIRC, those running NT don't have this problem, because the std shell there
(cmd.exe) does return the exit status of the command it runs.

who-says-ms-isn't-open-source<wink>?-ly y'rs  - tim

More information about the Python-list mailing list