Prev: idle 2.x and unicode literals
Next: subclass of object
From: Harishankar on 2 Apr 2010 06:17 I am writing a small app which requires input using stdin to the subprocess. I use the following technique: proc = subprocess.Popen (cmdargs, stdin=subprocess.PIPE) proc.stdin.write ("Something") proc.stdin.flush () .... proc.stdin.write ("something else") proc.stdin.flush () .... and so on. I cannot use communicate() because it waits till program termination and so obviously can be used once only. The problem is that I want to close the process and it's not responding either to proc.stdin.close() or even proc.terminate() which is in Python 2.6 (not in 2.5.x) So I am left with a mangled terminal. Is subprocess behaving funny or am I doing something wrong? I am not even sure if the proc.stdin.close () is respected because even without it, I am getting the same mangled state. I just want to control the commands using stdin.write and then close the process when done. -- Harishankar (http://harishankar.org http://literaryforums.org)
From: Harishankar on 2 Apr 2010 06:26 On Fri, 02 Apr 2010 10:17:55 +0000, Harishankar wrote: > I am writing a small app which requires input using stdin to the > subprocess. > > I use the following technique: > > proc = subprocess.Popen (cmdargs, stdin=subprocess.PIPE) > > proc.stdin.write ("Something") > proc.stdin.flush () > ... > proc.stdin.write ("something else") > proc.stdin.flush () > ... > > and so on. I cannot use communicate() because it waits till program > termination and so obviously can be used once only. > > The problem is that I want to close the process and it's not responding > either to proc.stdin.close() or even proc.terminate() which is in Python > 2.6 (not in 2.5.x) > > So I am left with a mangled terminal. > > Is subprocess behaving funny or am I doing something wrong? I am not > even sure if the proc.stdin.close () is respected because even without > it, I am getting the same mangled state. I just want to control the > commands using stdin.write and then close the process when done. Hmm... just two minutes after I posted this. I just added this proc.wait () after closing stdin and it works fine now. Still not sure whether I need the proc.stdin.close () though. -- Harishankar (http://harishankar.org http://literaryforums.org)
|
Pages: 1 Prev: idle 2.x and unicode literals Next: subclass of object |