A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-list/2005-September/320809.html below:

execute commands and return output

execute commands and return output execute commands and return outputbilliejoex 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

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4