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.

Thanks

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:
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
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...
8
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...
4
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')...
0
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...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
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...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
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. ...
0
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...
0
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...
0
hi
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...
0
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....
0
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.