Open3 / os.waitpid() bug

sragsdale at my-deja.com sragsdale at my-deja.com
Thu Aug 5 21:27:02 CEST 1999


I think I might have found a bug in os.waitpid, which is reflected in
Popen3, commands.getstatusoutput, and other functions that use this
call.  In a nutshell, the program incorrectly identifies return values
from a child process.

To test this, I wrote and compiled the following C program:

int main() {
  return (23);
}

I then ran it and checked that things were going as expected:

> cc foo.c
> ./a.out
> echo $?
23

All fine and good.  I then ran the command in Python:

> python
Python 1.5.2 (#8, Jul 13 1999, 17:39:45) [C] on irix646
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> from commands import *
>>> getstatusoutput('./a.out')
(5888, '')
>>> from popen2 import Popen3
>>> fh = Popen3("./a.out")
>>> fh.poll()
5888
>>>

In both cases, we didn't get the actual return value: we got something
much bigger.  I ended up discovering that for return value x, Python
thinks the child process returned 256*x.

Is this a bug?  Did I miss something in the Official Documentation?  I'm
just divinding each return value by 256 which seems to fix the problem,
but I'd rather understand this rather than just kludge my way around it.

ObUname:

> uname -a
IRIX64 bach 6.2 06101031 IP28


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.




More information about the Python-list mailing list