os.system output

Kalle Svensson kalle at gnupung.net
Wed Mar 21 12:02:07 EST 2001


Sez Jonathan Soons:
> I am trying to save the output of
> 
> >>>dirs = os.system('ls')
> 
> into a variable but I do not need any output to
> the screen (altho it doesn't hurt). How do I
> go about this?

Check out os.popen().

>>> dirs = os.popen("ls").read()

Peace,
  Kalle
-- 
Email: kalle at gnupung.net     | You can tune a filesystem, but you
Web: http://www.gnupung.net/ | can't tune a fish. -- man tunefs(8)
PGP fingerprint: 0C56 B171 8159 327F 1824 F5DE 74D7 80D7 BF3B B1DD
 [ Not signed due to lossage.  Blame Microsoft Outlook Express. ]




More information about the Python-list mailing list