how to interact with Windows cmd?

Nobody nobody at nowhere.com
Thu Jul 5 18:11:32 CEST 2012


On Wed, 04 Jul 2012 20:10:47 -0700, self.python wrote:

> 2. after this, I typed like "cd .." but I/O is already closed so I
> can't do another things..

Don't use .communicate() if you want to keep the child process alive.
Write to p.stdin and read p.stdout and p.stderr.

In general, you'll need to use a separate thread for each stream,
otherwise you risk deadlock. Look at the source code for the
.communicate() method for an example.

Also, unless you specifically need stdout and stderr to be separated, use
"stderr=subprocess.STDOUT". The problem with separating them is that
there's no way to determine the order in which data was written, so
there's no way to reconstruct the output as it would have appeared on the
console.




More information about the Python-list mailing list