python - redirecting output of pexpect to a file -
i tried capture output of pexpect in 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" 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
not receives output. file created empty.
you have forgotten expect child :) add this, instance:
child.expect(pexpect.eof)
Comments
Post a Comment