Python 将pexpect的输出重定向到文件

Python 将pexpect的输出重定向到文件,python,io-redirection,pexpect,Python,Io Redirection,Pexpect,我试图在一个文件中捕获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') >>>

我试图在一个文件中捕获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  

但是,
mylogfile.txt
不接收输出。该文件已创建,但为空。

您忘记了希望从子文件中获得某些信息:) 添加以下内容,例如:

child.expect(pexpect.EOF)

你忘了从孩子那里得到什么:) 添加以下内容,例如:

child.expect(pexpect.EOF)