running os commands [newbie]

Ryan Tracey ryant at thawte.com
Fri Jan 12 10:49:47 EST 2001


Hi

> I want to create a list call dfout[]
> In the list, I want to put the output of the df command.
> How do I go about doing this?  I have been trying to find this in the docs,
> no luck so far.

Something like this:

>>> import os
>>> df = os.popen('df').readlines()
>>> df
['Filesystem           1k-blocks      Used Available Use% Mounted
on\012', '/dev/hda4              5210204   2248020   2697516  46%
/\012']

Then you can go:

>>> for i in df:
...     print i
... 
Filesystem           1k-blocks      Used Available Use% Mounted on

/dev/hda4              5210204   2248020   2697516  46% /

...or whatever you might want to do ;-)

Cheers,
Ryan

--
Ryan Tracey 
Thawte Certification
South Africa



More information about the Python-list mailing list