2010-12-02 5 views
1

J'ai essayé de capturer la sortie de pexpect dans un fichier.rediriger la sortie de pexpect vers un fichier

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 
[email protected]:~/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 

Cependant mylogfile.txt ne reçoit pas la sortie. Le fichier est créé mais est vide.

Répondre

1

Vous avez oublié d'attendre quelque chose de l'enfant :) Ajouter ce, par exemple:

child.expect(pexpect.EOF) 
Questions connexes