Edward C. Jones wrote:
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:
ValueError: I/O operation on closed file

As defined in the docs. You can't use communicate() for what you're trying to do.

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.?

communicate is not the only way of communicating... use the stdin/stdout handles that are provided. You can very likely find examples of usage in the list archives.

-Peter
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to