output of shell command

Sheila King sheila at spamcop.net
Mon Feb 26 16:09:15 EST 2001


On Tue, 27 Feb 2001 07:39:57 +1100, Joe Connellan <joe at al.com.au> wrote in
comp.lang.python in article <3A9ABF1D.EE79FCD3 at al.com.au>:

:Thanks guys for the help, one note is that os.popen().readlines() of
:course will return a list of strings - lines of output, whereas
:commands.getoutput() will return a single string. So both will come in
:handy.
:
:Thanks again

You can return a single string by turning the readlines() into read()
like this:

os.popen().read()

Or, do this (silly):

"\n".join(os.popen("dir").readlines()))


--
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org/





More information about the Python-list mailing list