Skip stdin and stderr of child with pexpect
I'm controlling a child process using pexpect
(because subprocess
doesn't support pty's and I run into a deadlock with two pipes). The process creates a lot of output on stderr
, in which I'm not interested, and apparantly pexpect
also echoes back anything I write to its stdin
:
>>> import pexpect
>>> p = pexp开发者_如何学Cect.spawn('rev')
>>> p.sendline('Hello!')
7
>>> p.readline()
'Hello!\r\n'
>>> p.readline()
'!olleH\r\n'
How can I turn this off?
Using pty's is not quite the same as a pipe. If you don't put in in raw mode the tty driver will echo back the characters and perform other line editing. So to get a clean data path you need to also put the pty/tty in raw mode.
Since you are now dealing with a pseudo device you have only a single I/O stream. There is no distinction there between stdout and stderr (that is a userspace convention). So you will always see stdout and stderr mixed when using a pty/tty.
精彩评论