将pexpect的输出重定向到fi

2024-10-02 12:34:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图将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

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


Tags: 文件txtchildongrepaprptspexpect

热门问题