system return status on Windows

Tim Peters tim_one at email.msn.com
Thu Feb 24 20:42:29 EST 2000
[Milos Prudek
 Python 1.5.2, Pythonwin, Win98.
]

> I cannot get nonzero status from os.system() call in MS Windows.

That's OK -- neither can anyone else.

> Like this:
>
> print os.system('arj a test nonexistent_file')
>
> I have verified that errorlevel is raised,

Actually, you haven't:  you've verified that arj sets errorlevel, but that's
not how Microsoft's implementation of the C library function "system" (which
Python invokes) works.  MS's system actually acts like

    command.com /c arj a test nonexistent_file

and command.com *always* returns a 0 exit status.  That's what os.system
sees.  So you're stuck.

It may (or may not ... anyone know for sure?) work to install "a real shell"
instead, and set the MS envar COMSPEC to point to it.

You could also try os.spawnv or os.spawnve (but those only exist under
Windows).  BTW, don't expect os.popen to work sensibly under Windows either.

python-is-only-a-few-thousand-lines-of-excruciating-code-away-from-
    making-this-stuff-appear-to-work-under-windows-ly y'rs  - tim






More information about the Python-list mailing list