[英]redirecting output of pexpect to a file
I tried to capture the output of pexpect in a file. 我试图在文件中捕获pexpect的输出。
Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pexpect
>>> child = pexpect.spawn('iostat 3')
>>> fout = file('mylogfile.txt','w')
>>> child.logfile = fout
tazim@webdev:~/webexample$ ps -ef | grep iostat
tazim 4683 4675 0 12:49 pts/3 00:00:00 /usr/bin/iostat 3
tazim 4685 4560 0 12:51 pts/2 00:00:00 grep --color=auto iostat
However mylogfile.txt
does not receives the output. 但是,
mylogfile.txt
不会收到输出。 The file is created but is empty. 文件已创建但为空。
您忘记了对孩子的期望:)添加以下内容,例如:
child.expect(pexpect.EOF)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.