subprocess.Popen() problem

7stud bbxx789_05ss at yahoo.com
Tue Jun 26 16:38:30 EDT 2007


I have this program:

mytest.py
--------------
myinput = raw_input("Enter input: ")

if myinput == "hello":
    print "goodbye"
--------------

and I want to execute it using subprocess.Popen().  I tried the
following but it just hangs:

-----------
import subprocess

f = open("/Users/me/2testing/dir1/aaa.txt", "w")
my_path = "/Users/me/2testing/"
my_file = "mytest.py"

p = subprocess.Popen(["python", "mytest.py"], stdin=subprocess.PIPE,
                stdout = f,
                stderr = f,
                cwd = my_path
)

f.close()

p.stdin.write("hello")
p.wait()

f.open("/Users/me/2testing/dir1/aaa.txt")
print f.read()
------------




More information about the Python-list mailing list