Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > RE: Redirecting system output quietly

Reply
Thread Tools

RE: Redirecting system output quietly

 
 
Eddie Parker
Guest
Posts: n/a
 
      11-16-2004
Look at the 'popen' modules.

(I believe their under the os module).

-e-

-----Original Message-----
From: python-list-bounces+eddie=(E-Mail Removed)
[mailtoython-list-bounces+eddie=(E-Mail Removed)] On Behalf Of
Madhusudhanan Chandrasekaran
Sent: November 15, 2004 5:03 PM
To: http://www.velocityreviews.com/forums/(E-Mail Removed)
Subject: Redirecting system output quietly

Hi,
I am a newbie here. I want to know how to redirect os.system("ls -af")
to a string variable without it barfing the answer of ls -af on the
screen.

Thanks in advance,
Madhusudhanan.C
--
http://mail.python.org/mailman/listinfo/python-list

---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.788 / Virus Database: 533 - Release Date: 01/11/2004


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.788 / Virus Database: 533 - Release Date: 01/11/2004



 
Reply With Quote
 
 
 
 
StvB
Guest
Posts: n/a
 
      11-16-2004
cmdline = 'whatever command you want to run'
pipe = os.popen(cmdline + " 2>&1")
for line in pipe.readlines():
tempList.append(line)
rc = pipe.close()
if rc:
ErrorResult = 1
else:
fg.ErrorResult = 0



"Eddie Parker" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Look at the 'popen' modules.
>
> (I believe their under the os module).
>
> -e-
>
> -----Original Message-----
> From: python-list-bounces+eddie=(E-Mail Removed)
> [mailtoython-list-bounces+eddie=(E-Mail Removed)] On Behalf Of
> Madhusudhanan Chandrasekaran
> Sent: November 15, 2004 5:03 PM
> To: (E-Mail Removed)
> Subject: Redirecting system output quietly
>
> Hi,
> I am a newbie here. I want to know how to redirect os.system("ls -af")
> to a string variable without it barfing the answer of ls -af on the
> screen.
>
> Thanks in advance,
> Madhusudhanan.C
> --
> http://mail.python.org/mailman/listinfo/python-list
>
> ---
> Incoming mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.788 / Virus Database: 533 - Release Date: 01/11/2004
>
>
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.788 / Virus Database: 533 - Release Date: 01/11/2004
>
>
>



 
Reply With Quote
 
 
 
 
Hugo Gonz?lez
Guest
Posts: n/a
 
      11-16-2004
There's an even easier way to do this. You can use the "commands"
module:

http://www.python.org/doc/current/li...-commands.html

This is easier and faster than using popen, and will allow you to get
exit status (os.popen* won't let you)

Hugo


> > Hi,
> > I am a newbie here. I want to know how to redirect os.system("ls -af")
> > to a string variable without it barfing the answer of ls -af on the
> > screen.
> >
> > Thanks in advance,
> > Madhusudhanan.C

 
Reply With Quote
 
David Bolen
Guest
Posts: n/a
 
      11-16-2004
(E-Mail Removed) (Hugo Gonz?lez) writes:

> There's an even easier way to do this. You can use the "commands"
> module:
>
> http://www.python.org/doc/current/li...-commands.html
>
> This is easier and faster than using popen, and will allow you to get
> exit status (os.popen* won't let you)


Well, since the commands module is just a simple wrapper around the
os.popen() call, it's hard to see it giving you anything you can't get
with the call itself

You can certainly get the exit status from os.popen - it is returned
as the result of the close() operation. (Under Windows, for the
higher order popen* calls, you get the exit status from the close() on
the final of the multiple handles you close, while under Unix I think
you need to explicitly do a wait() on the returned handle).

One thing to be aware of with commands (although this shouldn't be a
problem for the OP in this case), is that it is Unix only, and won't
work properly under Windows.

-- David
 
Reply With Quote
 
Donn Cave
Guest
Posts: n/a
 
      11-16-2004
In article <(E-Mail Removed) >,
(E-Mail Removed) (Hugo Gonz?lez) wrote:

> There's an even easier way to do this. You can use the "commands"
> module:
>
> http://www.python.org/doc/current/li...-commands.html
>
> This is easier and faster than using popen, and will allow you to get
> exit status (os.popen* won't let you)


You can look at the implementation, it's a Python source file
commands.py in the library directory. I mention that because
you might be interested to see how it uses os.popen, and gets
the status.

Donn Cave, (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
Redirecting cout/cerr to System.out/System.err william.lichtenberger@gmail.com Java 0 09-17-2008 09:40 PM
Redirecting System.in , System.out to JTextArea ash Java 1 03-25-2008 07:50 AM
redirecting system output nahum_barnea@yahoo.com Perl Misc 6 07-24-2006 07:15 AM
How to "unattended" (or quietly) installed the .NET Framework 1.1. and SP1 for this Soren Mikkelsen ASP .Net 2 07-08-2005 11:00 AM
stdout funniness from os.system() calls when redirecting output Birch Python 3 10-21-2003 04:16 PM



Advertisments