Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Capturing output of os.system to a string

Reply
Thread Tools

Capturing output of os.system to a string

 
 
gerry.butler
Guest
Posts: n/a
 
      11-24-2009
How do I capture output to a string? For example, the output of
os.system('whoami').

I guess I need to redirect stdout, but I'm a total beginner, and I
haven't been able to find out from the tutorials how to do this.

 
Reply With Quote
 
 
 
 
Lie Ryan
Guest
Posts: n/a
 
      11-24-2009
gerry.butler wrote:
> How do I capture output to a string? For example, the output of
> os.system('whoami').
>
> I guess I need to redirect stdout, but I'm a total beginner, and I
> haven't been able to find out from the tutorials how to do this.
>


You can't with os.system; use subprocess module instead.
 
Reply With Quote
 
 
 
 
gerry.butler
Guest
Posts: n/a
 
      11-24-2009
Thank you. I'll look at subprocess.

I have since found that commands will do it too, eg,

(status, txt) = commands.getstatusoutput('whoami')

or txt = commands.getoutput('whoami')



 
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
Capturing output form console kaushik.krishnakumar@gmail.com Java 2 02-16-2006 04:27 AM
Capturing output form console kaushik.krishnakumar@gmail.com Java 0 02-15-2006 11:02 AM
capturing the output of a JSP Andy Fish Java 4 02-11-2004 03:07 PM
Capturing print output from a pdf file none Computer Support 3 08-05-2003 10:12 AM
Capturing ASPX output from another page Rick Strahl [MVP] ASP .Net 1 07-09-2003 07:34 PM



Advertisments