E
Edward C. Jones
I have a program named "octave" (a Matlab clone). It runs in a terminal,
types a prompt and waits for the user to type something. If I try
# Run octave.
oct = subprocess.Popen("octave", stdin=subprocess.PIPE)
# Run an octave called "startup".
oct.communicate("startup")
# Change directory inside octave.
oct.communicate("cd /home/path/to/my/dir")
I get:
Traceback (most recent call last):
File "./popen.py", line 29, in ?
oct.communicate("cd /home/path/to/my/dir")
File "/usr/local/lib/python2.4/subprocess.py", line 1044, in communicate
self.stdin.flush()
ValueError: I/O operation on closed file
How do I set up a subprocess so I can send it a command and get the
answer, then send it another command and get an answer, etc.?
types a prompt and waits for the user to type something. If I try
# Run octave.
oct = subprocess.Popen("octave", stdin=subprocess.PIPE)
# Run an octave called "startup".
oct.communicate("startup")
# Change directory inside octave.
oct.communicate("cd /home/path/to/my/dir")
I get:
Traceback (most recent call last):
File "./popen.py", line 29, in ?
oct.communicate("cd /home/path/to/my/dir")
File "/usr/local/lib/python2.4/subprocess.py", line 1044, in communicate
self.stdin.flush()
ValueError: I/O operation on closed file
How do I set up a subprocess so I can send it a command and get the
answer, then send it another command and get an answer, etc.?