commands.getstatusoutput result is not command line exit value!!!
hpsekhon at googlemail.com
Mon Oct 2 18:50:52 CEST 2006
ok, I was thinking of shifting using subprocess, guess I'd better do
that and forget about this waste of time.
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:
> 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
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list