469,572 Members | 1,306 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,572 developers. It's quick & easy.

Output of pexpect

Hi all,

I am using pexpect and I want to send output of pexpet to both stdout and log file concurrently.
Anybody know a solution for it please let me know.

Thanks

Oct 1 '08 #1
1 14431
On Sep 30, 8:48*pm, Anh Khuong <kq...@yahoo.comwrote:
Hi all,

I am using pexpect and I want to send output of pexpet to both stdout andlog file concurrently.
Anybody know a solution for it please let me know.
spawn class takes a 'logfile' parameter:
__init__(self, command, args=[], timeout=30, maxread=2000,
searchwindowsize=None, logfile=None, cwd=None, env=None)

More logging info at:
http://pexpect.sourceforge.net/pexpect.html

From the above link:
The logfile member turns on or off logging. All input and output will
be copied to the given file object. Set logfile to None to stop
logging. This is the default. Set logfile to sys.stdout to echo
everything to standard output. The logfile is flushed after each
write.

Example log input and output to a file::

child = pexpect.spawn('some_command')
fout = file('mylog.txt','w')
child.logfile = fout

Example log to stdout::

child = pexpect.spawn('some_command')
child.logfile = sys.stdout

The logfile_read and logfile_send members can be used to separately
log
the input from the child and output sent to the child. Sometimes you
don't want to see everything you write to the child. You only want to
log what the child sends back. For example::

child = pexpect.spawn('some_command')
child.logfile_read = sys.stdout

To separately log output sent to the child use logfile_send::

self.logfile_send = fout

I am not very sure if you can do the logging to two different files at
the same time (ie sys.stdout as well as another file-object). I guess
that's your question. The above should give you a starting point to
explore. [May be give a fake file like object and intercept the write/
flush calls?]

Karthik
>
Thanks
Oct 1 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.