Is this a genuine bug?

Tim Peters tim_one at email.msn.com
Sun May 9 03:44:25 EDT 1999


[posted and mailed]

[Eric S. Raymond]
> # The following functions should become part of the library os.py file

No, that's not a genuine bug <wink>.  I fwd'ed the whole msg to Guido,
though, cuz he'll be out of town & out of touch for a while.

> ...
> # 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`

I expect that's expected.  From the 1.5.2 docs (see the last sentence):

    popen (command[, mode[, bufsize]])
    Open a pipe to or from command. ...
    The exit status of the command (encoded in the format specified
    for wait()) is available as the return value of the close() method
    of the file object, except that when the exit status is zero
    (termination without errors), None is returned.

If you want an int all the time, e.g.

    status = rfp.close() or 0

will do it.

begging-the-real-question-ly y'rs  - tim






More information about the Python-list mailing list