473,396 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 15135
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 (so that I can kill it) I can do one or other...
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 a password on the rest of the nodes. It does...
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') and want the result of the output in a vector,...
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 logfile. class forkwriter(object): def...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.