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

M

mrstephengross

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
 
K

Karthik Gurusamy

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?
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
 
G

Gabriel Genellina

En Wed, 24 Oct 2007 16:07:44 -0300, mrstephengross
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?

Read the docs again...
 
0

0x7f494e

четверг, 25 октÑÐ±Ñ€Ñ 2007 г., 1:12:31 UTC+5 пользователь Jean-Paul Calderone напиÑал:
Jean-Paul

Big Thanks! :))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top