473,566 Members | 3,342 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Greetings.
I am performing:

commands.getsta tusoutput("rsyn c <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.getsta tusoutput() 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.bi z http://autopoweroff.sourceforge.net
(Logiciel)
Jul 18 '05 #1
2 2340
Hans Deragon wrote:
Greetings.
I am performing:

commands.getsta tusoutput("rsyn c <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.getsta tusoutput() 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**********@i nfo4.fnal.gov>,
Matt Leslie <ma***********@ hotmail.com> wrote:
Hans Deragon wrote:
Greetings.
I am performing:

commands.getsta tusoutput("rsyn c <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.getsta tusoutput() 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.washingt on.edu
Jul 18 '05 #3

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

Similar topics

2
5315
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 "amateur hacker" :-) was very pleased to discover at one stage how to run processes in parallel using python, which is powerful technology to say the...
8
15081
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 execute the os.system('cd newdirectory; make all'), but how do I redirect stdout of the new subshell created by the os.system call? Any help would be...
6
5612
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.* . I have tried the simplest method of capturing stdout, stderr via: saveout = sys.stdout sys.stdout = file_obj
1
5365
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 application (VB.NET) will start a process, redirect its stdout and capture that process' output, displaying it in a window. I've written a component...
7
11619
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 output to a file, say fileB.txt. I'm trying to implement a program that would then take the two files and use them separately. By the way, I'm on...
13
3136
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 necessary, why, and what their alternative is in Python?
1
3760
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 capture the results of the compile and display them in a RichTextBox. The problem I'm having is that when I intentionally introduce an error in the C...
2
8457
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 separate files, but would rather keep the 2 flows together. Is it correct to do this: stderr=freopen(LogFile, "w", stderr);...
4
5763
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 best regards, Wilbert Berendsen
0
7893
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8109
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7645
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5485
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2085
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
926
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.