popen4 - get exit status

Benjamin Kaplan benjamin.kaplan at case.edu
Mon Aug 27 19:02:28 EDT 2012


On Aug 27, 2012 3:47 PM, "Tim Johnson" <tim at akwebsoft.com> wrote:
>
> 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

The popen* functions are deprecated. You should use the subprocess module
instead.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20120827/d8ae07ca/attachment.html>


More information about the Python-list mailing list