On Jun 26, 3:38 pm, 7stud <[EMAIL PROTECTED]> wrote: > 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() > ------------
Never tried this, but I think you need to use the communicate method detailed here: http://docs.python.org/dev/lib/node537.html If that doesn't work, you might look into using the threading module and its methods. Or there could be a flush command that I can't find... Mike -- http://mail.python.org/mailman/listinfo/python-list