将 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')
>>> 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
没有收到输出。文件已创建但为空。
I tried to capture the output of pexpect in a file.
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. The file is created but is empty.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你忘记了对孩子有什么期望:)
添加这个,例如:
You have forgotten to expect something from the child :)
Add this, for instance: