commands.getstatusoutput result is not command line exit value!!!

Hari Sekhon hpsekhon at googlemail.com
Mon Oct 2 12:50:52 EDT 2006


ok, I was thinking of shifting using subprocess, guess I'd better do 
that and forget about this waste of time.

thanks

Hari Sekhon



Fredrik Lundh wrote:
> Hari Sekhon wrote:
>
>   
>> I'm sorry, this may seem dense to you but I have to ask. What on earth 
>> are you talking about?
>>     
>  >
>   
>> Why is it shifted 8 bits to the left? Why is there bitshifting at all? 
>> Why doesn't commands give the same exit value as os.system() and the 
>> unix cli?
>>     
>
> because that's how Unix's wait() operation returns the status code (as 
> mentioned in the "commands" section of the library reference).
>
> you can use the os.WIFEXITED(status) and os.WEXITSTATUS(code) helpers to 
> convert between wait return codes and signal numbers/exit codes.  see:
>
>      http://docs.python.org/lib/os-process.html
>
> or you can forget about the obsolete "commands" module, and use the new 
> subprocess module instead; e.g.
>
> def getstatusoutput(command):
>      from subprocess import Popen, PIPE, STDOUT
>      p = Popen(command, stdout=PIPE, stderr=STDOUT, shell=True)
>      s = p.stdout.read()
>      return p.wait(), s
>
> print getstatusoutput("ls -l /bin/ls")
> (0, '-rwxr-xr-x    1 root     root        68660 Aug 12  2003 /bin/ls\n')
>
> the subprocess module is highly flexible; see the library reference for 
> details.
>
> </F>
>
>   
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20061002/ed0a0c67/attachment.html>


More information about the Python-list mailing list