472,353 Members | 1,898 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

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.


Oct 1 '08 #1
1 14850
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:

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

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
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?]

Oct 1 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Hugh Macdonald | last post by:
I'm calling a command from within a python script and I need to be able to both catch the output (stdout and stderr) from it and also have the PID...
by: supercomputer | last post by:
I have a script that I cycle through nodes connect to them and run uptime to get some information. I run the script as root so it doesn't require...
by: alexLIGO | last post by:
Hi, I would like to execute some command in python on the bash, e.g. os.system('globus-job-run mike4.cct.lsu.edu/jobmanager-pbs -l /bin/date')...
by: Lie Ryan | last post by:
On Tue, 30 Sep 2008 20:48:12 -0700, Anh Khuong wrote: One way is to create a file-like object that forked the output to stdout and the...
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.