473,387 Members | 1,303 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,387 software developers and data experts.

Fetching the stdout & stderr as it flows from a unix command.

Greetings.
I am performing:

commands.getstatusoutput("rsync <params>");

rsync takes a long time and prints out a steady stream of lines
showing which file it is currently working on.

Unfortunatly, the commands.getstatusoutput() fetchs everything and
there is no way to ask it to copy the output of the command to
stdout/stderr. Thus when rsync takes an hour, I have no clue where it
is at.

Anybody has a suggestion how to let stdout/stderr print out on the
console when calling a unix command?
Best regards,
Hans Deragon
--
Consultant en informatique/Software Consultant
Deragon Informatique inc. Open source:
http://www.deragon.biz http://facil.qc.ca (Promotion du libre)
mailto://ha**@deragon.biz http://autopoweroff.sourceforge.net
(Logiciel)
Jul 18 '05 #1
2 2333
Hans Deragon wrote:
Greetings.
I am performing:

commands.getstatusoutput("rsync <params>");

rsync takes a long time and prints out a steady stream of lines
showing which file it is currently working on.

Unfortunatly, the commands.getstatusoutput() fetchs everything and
there is no way to ask it to copy the output of the command to
stdout/stderr. Thus when rsync takes an hour, I have no clue where it
is at.

Anybody has a suggestion how to let stdout/stderr print out on the
console when calling a unix command?


Perhaps you could use the popen2 module. popen2.popen2() returns file
handles for stdout and stderr. You could read from these and print the
output to the screen while the process runs.

Matt
Jul 18 '05 #2
In article <c9**********@info4.fnal.gov>,
Matt Leslie <ma***********@hotmail.com> wrote:
Hans Deragon wrote:
Greetings.
I am performing:

commands.getstatusoutput("rsync <params>");

rsync takes a long time and prints out a steady stream of lines
showing which file it is currently working on.

Unfortunatly, the commands.getstatusoutput() fetchs everything and
there is no way to ask it to copy the output of the command to
stdout/stderr. Thus when rsync takes an hour, I have no clue where it
is at.

Anybody has a suggestion how to let stdout/stderr print out on the
console when calling a unix command?


Perhaps you could use the popen2 module. popen2.popen2() returns file
handles for stdout and stderr. You could read from these and print the
output to the screen while the process runs.


Carefully, though. If there's no particular reason to keep
the two streams distinct, then it might be a good idea to
merge them, so there is only one file to read.

Otherwise, to read two files in parallel, see select.select.

With select, I would not use the file objects that Popen3 creates,
rather use the pipe file descriptors directly (the integer number
returned by the file object fileno() method, which can be used
with core UNIX/POSIX I/O functions like os.read.) File objects
are buffered, which makes select more or less useless; you can
turn off buffering, but that makes functions like readline()
horribly inefficient. It isn't very hard to live without the
file object here.

And then note that rsync may not deliver its output as promptly
when talking to a pipe. That can be solved too, but it's
usually not worth the trouble.

Donn Cave, do**@u.washington.edu
Jul 18 '05 #3

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

Similar topics

2
by: Andrei D. | last post by:
Hello Python newsgroup, In the process of developing a big ssh wrapper for sending commands to multiple hosts over the last few months, I (almost accidentally, considering I'm really just an...
8
by: Terry Gray | last post by:
Using Python 2.2 in Debian linuxI am trying to change to a different directory, execute a 'make all' command, and redirect the output of the subshell to a PyQt window... I should be able to...
6
by: Tsai Li Ming | last post by:
Dear all, I have a problem with a redirecting stdout and stderr. I am a top level module and has no control over the imported modules that are making system calls such as os.system or popen2.* ....
1
by: Oz | last post by:
This is long. Bear with me, as I will really go through all the convoluted stuff that shows there is a problem with streams (at least when used to redirect stdout). The basic idea is that my...
7
by: Andre | last post by:
Hi, I have a program that sends some output to stdout and some to stderr. I need to separate the two using the command-line so that I direct stderr output to a file, say fileA.txt, and stdout...
13
by: Vincent Delporte | last post by:
Hi I'm a Python newbie, and would like to rewrite this Perl scrip to be run with the Asterisk PBX: http://www.voip-info.org/wiki/view/Asterisk+NetCID Anyone knows if those lines are...
1
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post by:
Hello, I have a C# application in which I start another process which produces output to stdout and stderr. In fact, that process is the uSoft VS2005 C/C++ compiler itself! I would like to...
2
by: Guillaume Dargaud | last post by:
Hello all, a while ago I was pointed towards freopen as a way to redirect stderr to a log file. It works great, but apparently the app also writes a few lines to stdout. Now I could redirect to 2...
4
by: Wilbert Berendsen | last post by:
Hi, using pty.spawn() it seems that stderr output of the spawned process is directed to stdout. Is there a way to keep stderr separate and only direct stdin and stdout to the pty? TIA, w...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.