簡體   English   中英

將pexpect的輸出重定向到文件

[英]redirecting output of pexpect to 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

但是, mylogfile.txt不會收到輸出。 文件已創建但為空。

您忘記了對孩子的期望:)添加以下內容,例如:

child.expect(pexpect.EOF)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM