7
7stud
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()
------------
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()
------------