Problem with sys.exit()

Donn Cave donn at oz.net
Sat Jul 1 02:14:42 EDT 2000


Quoth "Steven M. Castellotti" <scastell at sas.upenn.edu>:
| 	I'm having some difficulty with a particular python script. I'm taking
| gzipped log files and calling zcat (from the command line) with one
| script (feeder.py), which pipes the output to the second script
| (parser.py). The second script addes up few things, and I want it to
| report the final total back to the feeder script. I tried passing it via
| sys.exit() (ugly I know, but it seemed like a good idea at the time) but
| when I use the numbers in the feeder script, the numbers are way off:
|
| End of parser.py:
|
| print total_registrations
| sys.exit(total_registrations)
|
| 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.
|
| 	Any ideas about what might be wrong, or perhaps a better way to do
| this? If there was a way to read a gzip'd text file directly into python
| that'd probably take care of it, but why isn't this working?

Try shifting the result of os.system() right 8 bits.  Also note that
you have only 7 or 8 bits to work with here, so it will work for 3
or 30 but not 300.  It wouldn't hurt all that much to use popen().

	Donn Cave, donn at oz.net



More information about the Python-list mailing list