Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Capturing output of os.system to a string

16 views
Skip to first unread message

gerry.butler

unread,
Nov 23, 2009, 8:27:50 PM11/23/09
to
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.

Lie Ryan

unread,
Nov 23, 2009, 8:40:00 PM11/23/09
to

You can't with os.system; use subprocess module instead.

gerry.butler

unread,
Nov 23, 2009, 9:11:08 PM11/23/09
to
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')

0 new messages