popen2 question

D

David Bear

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?
 
L

Lawrence D'Oliveiro

David Bear said:
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?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

threading+popen2 hang 3
popen2 1
popen2 psql 2
Having trouble converting popen2 to subprocess 3
Possible problem with popen2 module 2
Problem with select.poll and popen2 1
A better popen2 4
Trouble with popen2 4

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top