popen2 question

Discussion in 'Python' started by David Bear, Jun 22, 2006.

  1. David Bear

    David Bear Guest

    I'm using popen2 and getting an extra 1 at the end of my output. I didn't
    see where this was explained in the docs so I clearly don't understand the
    behavior. My code is simple.

    (input, output) = os.popen2('whackyperlprogram')
    results = output.read()
    rc = output.close()
    print results

    The documentation said that the return code would returned with the stdout
    handled was closed.

    This does not explain why I am getting a '1' appended to the end of the
    results.

    And yes, there is some functionality bundled in a perl program that I need
    -- and I don't have time to reimplement what was written in perl. When I
    run the perl code directly, I get the output I want. When I run it through
    the os.popen2 module, I get an additional 1 appended. (It's all string
    output)

    Is this normal behavior for this module? What am I missing?
    --
    David Bear
    -- let me buy your intellectual property, I want to own your thoughts --
     
    David Bear, Jun 22, 2006
    #1
    1. Advertising

  2. In article <3026518.PBSJIyfHH0@teancum>,
    David Bear <> wrote:

    >I'm using popen2 and getting an extra 1 at the end of my output. I didn't
    >see where this was explained in the docs so I clearly don't understand the
    >behavior. My code is simple.
    >
    >(input, output) = os.popen2('whackyperlprogram')
    >results = output.read()
    >rc = output.close()
    >print results


    What if, for comparison, you try running a trivial program that produces
    no output:

    (input, output) = os.popen2('/bin/true')
    results = output.read()
    rc = output.close()
    print results

    Do you still get the "1" at the end?
     
    Lawrence D'Oliveiro, Jun 26, 2006
    #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. Guy

    popen2

    Guy, Aug 12, 2003, in forum: Python
    Replies:
    1
    Views:
    2,852
    Donn Cave
    Aug 12, 2003
  2. cherico

    popen2 with large input

    cherico, Jan 29, 2004, in forum: Python
    Replies:
    2
    Views:
    330
    Jeff Epler
    Jan 29, 2004
  3. Diez B. Roggisch

    popen2 trouble

    Diez B. Roggisch, Apr 2, 2004, in forum: Python
    Replies:
    2
    Views:
    323
    Diez B. Roggisch
    Apr 5, 2004
  4. A. Lloyd Flanagan

    Possible problem with popen2 module

    A. Lloyd Flanagan, Apr 30, 2004, in forum: Python
    Replies:
    2
    Views:
    320
    A. Lloyd Flanagan
    May 3, 2004
  5. Guest
    Replies:
    1
    Views:
    481
    Donn Cave
    Jun 15, 2004
Loading...

Share This Page