Problem with sys.exit()

Thomas Wouters thomas at xs4all.nl
Fri Jun 30 12:02:59 EDT 2000


On Fri, 30 Jun 2000 11:07:22 -0500, Steven M. Castellotti
<scastell at sas.upenn.edu> wrote:

>Relevant portion of feeder.py:

>grand_total = grand_total + \
>  os.system('zcat %s | python authlog_parser.py' % (filename) )
>print "%i" % os.system('zcat %s | python authlog_parser.py' % (filename)
>)
>print "Grand Total: %s" % grand_total

>But my output looks something like this:

>3
>768
>Grand Total: 1024

>	...where the "3" is the actual total getting passed into sys.exit(),
>768 is what parser.py is recieving, and 1024 being the total.

Yes. Exactly how it should be ;-)

>From the library documentation:

system (command) 
    Execute the command (a string) in a subshell. This is implemented by
    calling the Standard C function system(), and has the same limitations.
    Changes to posix.environ, sys.stdin, etc. are not reflected in the
    environment of the executed command. The return value 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. Note that POSIX does not
    specify the meaning of the return value of the C system() function, so
    the return value of the Python function is system-dependent.
    Availability: Unix, Windows.

And the documentation for wait():

wait () 
    Wait for completion of a child process, and 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. Availability: Unix.

Basically, if you want the number as passed to 'sys.exit()', you divide the
return value by 256 (or shift right by 8 bits, which is the same thing.)

And when you do that with your exitcode:

>>> 786/256
3
>>> 786>>8
3


Regards,
	Thomas.



More information about the Python-list mailing list