execute commands and return output
Fredrik Lundh
fredrik at pythonware.com
Sat Sep 10 06:20:22 EDT 2005
"billiejoex" wrote:
> Hi all. I'm searching for a portable (working on *nix and win32) function that executes a system command and encapsulate its
> output into a string.
> Searching for the web I found this:
>
> os.popen('command').read()
>
> It is perfect but when che command return an error the funciotn returns an empy string.
> Does it is possible to return stdout and stderr too?
see the variations popen2, popen3 and popen4:
http://docs.python.org/lib/os-newstreams.html
or use the subprocess module:
http://docs.python.org/lib/module-subprocess.html
</F>
More information about the Python-list
mailing list