please help me understand os.system() result

Duncan Booth duncan at NOSPAMrcp.co.uk
Tue May 20 09:59:37 EDT 2003


Eric Brunel <eric.brunel at pragmadev.com> wrote in
news:bad975$ju1$1 at news-reader12.wanadoo.fr: 

> According to the library reference ( 
> http://www.python.org/doc/current/lib/os-process.html#l2h-1226 ):
> 
> "The return value [of os.system] is the exit status of the process
> encoded in the format specified for wait(), except on Windows 95 and
> 98, where it is always 0." 
> 
> So let's go two paragraphs further for the doc of the wait function:
> 
> "[...] return a tuple containing its pid and exit status indication: a
> 16-bit number, whose low byte is the signal number that killed the
> process, and whose high byte is the exit status (if the signal number
> is zero); the high bit of the low byte is set if a core file was
> produced." 
> 

It looks to me as though the documentation is slightly broken at least on 
Windows systems. It says the return value is in the format specified for 
wait, but wait is not implemented on Windows systems. It also says that the  
return value is system dependant (which is true). The line saying it is the 
same as for wait should qualify that as only being true on Unix systems. On 
Windows 2k (and I presume NT and XP) the exit code is returned directly.

>>> os.system('''python -c "import sys; sys.exit(23)"''')
23

-- 
Duncan Booth                                             duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?




More information about the Python-list mailing list