Easiest way to get exit code from os.popen()?
Karthik Gurusamy
kar1107 at gmail.com
Wed Oct 24 16:16:06 EDT 2007
On Oct 24, 12:07 pm, mrstephengross <mrstephengr... at hotmail.com>
wrote:
> 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?
>>> 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
More information about the Python-list
mailing list