Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Fetching the stdout & stderr as it flows from a unix command.

Reply
Thread Tools

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

 
 
Hans Deragon
Guest
Posts: n/a
 
      06-04-2004
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://(E-Mail Removed) http://autopoweroff.sourceforge.net
(Logiciel)
 
Reply With Quote
 
 
 
 
Matt Leslie
Guest
Posts: n/a
 
      06-04-2004
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
 
Reply With Quote
 
 
 
 
Donn Cave
Guest
Posts: n/a
 
      06-04-2004
In article <c9qi42$908$(E-Mail Removed)>,
Matt Leslie <(E-Mail Removed)> 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, http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Netflow - Duplicate Packets or Flows sillz Cisco 2 05-21-2009 09:09 PM
Re: and so the merda flows! Pennywise@DerryMaine.Gov Computer Support 0 11-28-2008 01:41 AM
work flows in ruby on rails katthi Ruby 1 06-02-2007 04:36 PM
Number of cached deny-flows for ACL log has reached limit (4096) caroline brunel Cisco 0 12-09-2004 04:40 PM
redirecting stderr and stdout Jon Landenburer Perl 1 05-13-2004 07:38 AM



Advertisments