Is this a genuine bug?

Eric S. Raymond esr at snark.thyrsus.com
Sun May 9 02:21:19 EDT 1999


import os

# The following functions should become part of the library os.py file

def WEXITSTATUS(val):
    # Like ANSI WEXISTATUS but returns o.o.b. None if process exited abnormally
    lowbits = val & 0377
    if lowbits == 0:
        return val >> 8
    else:
        return None

def WSTOPSIG(val):
    # Like ANSI WSTOPSIG but returns o.o.b. None if process was not stopped
    if (val & 0377) == 0177:
        return val >> 8
    else:
        return None

def WTERMSIG(val):
    # Like ANSI WTERMSIG but returns o.o.b. None if process was not stopped
    lowbits = val & 0377
    if lowbits and lowbits != 0177:
        return lowbits
    else:
        return None

def WCORE(ret):
    # No ANSI equivalent
    return (val & 0200) != 0

# This exhibits the behavior the documentation leads me to expect.
fp = os.popen("exit 3")
foo = fp.close()
print "Status of `exit 3`:", WEXITSTATUS(foo)

# This does not.  Rather than returning an int as advertised,
# the close method returns None.
rfp = os.popen("tar cf - .", "r")
while 1:
    buf = rfp.read(4096)
    if not buf:
        break;
status = rfp.close()
print "Status of `tar -cf`:", `status`
-- 
		<a href="http://earthspace.net/~esr">Eric S. Raymond</a>




More information about the Python-list mailing list