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

0x7f494e at gmail.com 0x7f494e at gmail.com
Sun Sep 15 19:35:50 EDT 2013


четверг, 25 октября 2007 г., 1:12:31 UTC+5 пользователь Jean-Paul Calderone написал:
> On Wed, 24 Oct 2007 19:07:44 -0000, mrstephengross <mrstephengross 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?
> 
>   >>> import os
>   >>> os.WEXITSTATUS(1280)
>   5
>   >>>
> 
> Jean-Paul

Big Thanks! :))



More information about the Python-list mailing list