Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Easiest way to get exit code from os.popen()?

5,025 views
Skip to first unread message

mrstephengross

unread,
Oct 24, 2007, 3:07:44 PM10/24/07
to
Hi folks. I'm using os.popen() to run a command; according to the
documentation, the filehandle.close() oepration is suppsoed to return
the exit code. However, when I execute something like "exit 5",
close() returns 1280. Here's the code:

pipe = os.popen("exit 5")
print pipe.close() # prints 1280

Am I doing something wrong? Is there an easier way to get the exit
code?

Thanks,
--Steve

Jean-Paul Calderone

unread,
Oct 24, 2007, 4:12:31 PM10/24/07
to pytho...@python.org

>>> import os
>>> os.WEXITSTATUS(1280)
5
>>>

Jean-Paul

Karthik Gurusamy

unread,
Oct 24, 2007, 4:16:06 PM10/24/07
to
On Oct 24, 12:07 pm, mrstephengross <mrstephengr...@hotmail.com>
wrote:

>>> print "%#x" % 1280
0x500 # first byte is your exit code; second gives signal info if
any
>>>

In any case, the best approach is to use the os module to interpret it
as given in other post (os.WEXITSTATUS(1280))

Karthik

>
> Thanks,
> --Steve


Gabriel Genellina

unread,
Oct 29, 2007, 12:18:54 AM10/29/07
to pytho...@python.org
En Wed, 24 Oct 2007 16:07:44 -0300, mrstephengross
<mrsteph...@hotmail.com> escribi�:

Read the docs again...

--
Gabriel Genellina

0x7f...@gmail.com

unread,
Sep 15, 2013, 7:35:50 PM9/15/13
to
четверг, 25 октября 2007 г., 1:12:31 UTC+5 пользователь Jean-Paul Calderone написал:
Big Thanks! :))
0 new messages