open2 problem

M

mapik.ua

Hi. I have such problem with os.popen2 function:

//test.py file
#!/usr/local/bin/python
print "start"
x= raw_input()
print "end"

//main.py file
#!/usr/local/bin/python
import os
i,o = os.popen2('./tester.py')
print o.readline()
i.write("hi")
print o.readline()
i.close()
o.close()

When I run main.py its hung so I break it running and get exception
error:
Traceback (most recent call last):
File "./tester.py", line 4, in ?
x= raw_input()
Traceback (most recent call last):
KeyboardInterrupt
File "./c.py", line 5, in ?
print o.readline()
KeyboardInterrupt

But if I in main.py make some changes its work fine, but i need to read
first line for analyzing:
//main.py file
#!/usr/local/bin/python
import os
i,o = os.popen2('./tester.py')
i.write("hi")
print o.readline()
print o.readline()
i.close()
o.close()
 
F

Felipe Almeida Lessa

Em Sex, 2006-03-10 às 04:49 -0800, (e-mail address removed) escreveu:
Hi. I have such problem with os.popen2 function:

Why don't you use the subprocess module? See
http://docs.python.org/lib/module-subprocess.html

--
"Quem excele em empregar a força militar subjulga os exércitos dos
outros povos sem travar batalha, toma cidades fortificadas dos outros
povos sem as atacar e destrói os estados dos outros povos sem lutas
prolongadas. Deve lutar sob o Céu com o propósito primordial da
'preservação'. Desse modo suas armas não se embotarão, e os ganhos
poderão ser preservados. Essa é a estratégia para planejar ofensivas."

-- Sun Tzu, em "A arte da guerra"
 
M

mapik.ua

Why don't you use the subprocess module?

I have tried subprocess module and got the same problem
 
D

Dennis Lee Bieber

When I run main.py its hung so I break it running and get exception
error:

Strangely, on WinXP, it doesn't hang -- it sees the "start" line,
but then prints blank (null?) lines for the rest.

I do have one suggestion though.

raw_input() is waiting for a line of text. You might want to put a
line ending on the write to the pipe.
--
 

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

Members online

Forum statistics

Threads
474,289
Messages
2,571,448
Members
48,126
Latest member
ToneyChun2

Latest Threads

Top