popen4 - get exit status

Tim Johnson tim at akwebsoft.com
Mon Aug 27 18:39:38 EDT 2012


In bash I do the following:
linus:journal tim$ /home/AKMLS/cgi-bin/perl/processJournal-Photo.pl hiccup
-bash: /home/AKMLS/cgi-bin/perl/processJournal-Photo.pl: No such file or directory
linus:journal tim$ echo $?
127

In python, use os.popen4 I do the following:
>>> fin,fout = os.popen4('/home/AKMLS/cgi-bin/perl/processJournal-Photo.pl hiccup;echo $?')
>>> results = fout.readlines()
>>> results
['/bin/sh: /home/AKMLS/cgi-bin/perl/processJournal-Photo.pl: No such file or directory\n', '127\n']

Well, I got the exit code as the last item in the results, but I'm wondering if
there is a better way. From help(os) - I don't find any variables dedicated to
holding exit status.

Any ideas?
thanks
-- 
Tim 
tim at tee jay forty nine dot com or akwebsoft dot com
http://www.akwebsoft.com



More information about the Python-list mailing list