execute commands and return output
billiejoex
billiejoex at fastwebnet.it
Sat Sep 10 06:37:34 EDT 2005
Thank you for your help but I'm searching a different way.
Moreover it doesn't work always (for exaple: try a 'dir' command).
Because of I'm implementing a remote shell the
[[os.popen('command').read()]] rapresents the best for me because it can
also accepts arguments direclty (for example:
os.popen('netstat -a -n -o').read() and this is a great advantage.
I was looking at sys.stdout and sys.stderr. Can they be helpful?
Cheers
> Use subprocess:
>
> from subprocess import Popen, PIPE
> proc = Popen(['command', 'arg', 'arg'], stdout=PIPE, stderr=PIPE)
> return_code = proc.wait()
> if return_code == 0:
> print "Success:\n%s" % proc.stdout.read()
> else:
> print "Failure %s:\n%s" % (return_code, proc.stderr.read())
More information about the Python-list
mailing list