popen2 question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • David Bear

    #1

    popen2 question

    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('whac kyperlprogram')
    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 --
  • Lawrence D'Oliveiro

    #2
    Re: popen2 question

    In article <3026518.PBSJIy fHH0@teancum>,
    David Bear <david.bear@asu .edu> wrote:
    [color=blue]
    >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('whac kyperlprogram')
    >results = output.read()
    >rc = output.close()
    >print results[/color]

    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?

    Comment

    Working...