calling applications from python

Martin von Loewis loewis at informatik.hu-berlin.de
Thu Aug 9 13:19:46 EDT 2001


"Jesper Olsen" <jolsen at voxgeneration.com> writes:

> It is possible to call applications from a python program using, e.g.
> the os.system command:
> 
> os.system("ls -l")
> 
> Is it possible to attach the output from this command to a file?
> I would like to be able to read this output, instead of just sending it to
> stdout.

Certainly, that would be

p = os.popen("ls -l")
output = p.read()

Of course, if it is really ls(1) that you are after, I recommend to
use os.listdir instead, combined with os.stat.

Regards,
Martin



More information about the Python-list mailing list