emulating `` shell operator in Python?

Adrian Eyre a.eyre at optichrome.com
Fri Dec 3 09:24:03 EST 1999


> - But the really tricky case is to catch in a string the output of a
> *shell* command, such as os.system('ls').
> The above strategy doesnt work because the command executes in a
> sub-shell (external to python) with its own stdout and stderr.

import os

f = os.popen("ls", "r")
s = f.read()
f.close()
print s

--------------------------------------------
Adrian Eyre <mailto:a.eyre at optichrome.com>
Optichrome Computer Solutions Ltd
Maybury Road, Woking, Surrey, GU21 5HX, UK
Tel: +44 1483 740 233  Fax: +44 1483 760 644
http://www.optichrome.com 
--------------------------------------------





More information about the Python-list mailing list