os.popen varies return type depending on exit status?

Discussion in 'Python' started by David M. Wilson, Mar 5, 2004.

  1. Hi there, on Linux:

    >>> [ type(popen(cmd).close()) for cmd in ( 'true', 'foo' ) ]

    sh: line 1: foo: command not found
    [<type 'NoneType'>, <type 'int'>]


    This feels inconsistent to me, and it just bit me because I was
    expecting a 0 exit status on success, not None. Does close() return
    this for historic reasons?


    David.
     
    David M. Wilson, Mar 5, 2004
    #1
    1. Advertising

  2. David M. Wilson

    Donn Cave Guest

    In article <>,
    (David M. Wilson) wrote:

    > Hi there, on Linux:
    >
    > >>> [ type(popen(cmd).close()) for cmd in ( 'true', 'foo' ) ]

    > sh: line 1: foo: command not found
    > [<type 'NoneType'>, <type 'int'>]
    >
    >
    > This feels inconsistent to me, and it just bit me because I was
    > expecting a 0 exit status on success, not None. Does close() return
    > this for historic reasons?


    The close function wraps either fclose(3) or pclose(3),
    and I don't believe it actually knows which. They return
    the same 0 value on success, so in this case you see fclose
    behavior. Maybe that is for historic reasons, since in
    principle I don't think it would hurt anything for fclose
    to return 0.

    Donn Cave,
     
    Donn Cave, Mar 5, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jacob navia
    Replies:
    3
    Views:
    578
    Nick Keighley
    Feb 24, 2010
  2. Keith Thompson
    Replies:
    10
    Views:
    716
    Tim Rentsch
    Mar 3, 2010
  3. Garance A Drosihn

    Exit status on cmd executed via popen()

    Garance A Drosihn, Nov 24, 2003, in forum: Ruby
    Replies:
    3
    Views:
    908
    Gennady
    Nov 25, 2003
  4. Claudio Jeker

    IO#popen and exit status

    Claudio Jeker, Mar 20, 2006, in forum: Ruby
    Replies:
    7
    Views:
    200
    Tanaka Akira
    Mar 28, 2006
  5. kaleem
    Replies:
    8
    Views:
    880
    Tad McClellan
    Dec 14, 2006
Loading...

Share This Page