simplest way to run external commands ! <br><br>import os <br>cmd=&quot;/usr/bin/ssh <a href="http://10.0.0.20">10.0.0.20</a> uptime&quot;<br>os.popen(cmd)<br><br>my cmd is just an example, use any cmd you want &amp; its output will be displayed to you.<br>
hope this helps<br><br><br><br><br><div class="gmail_quote">On Thu, Mar 13, 2008 at 12:05 PM, Kent Johnson &lt;<a href="mailto:kent37@tds.net">kent37@tds.net</a>&gt; wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="Ih2E3d">Allen Fowler wrote:<br>
&gt; Hello,<br>
&gt;<br>
&gt; I need to call an external command line .exe utility from my Python script.<br>
&gt;<br>
&gt; What is the best way to capture the output (if any) and (optionally) direct it to my normal standard output?<br>
<br>
</div>subprocess.Popen().communicate() will do it:<br>
<br>
In [1]: import subprocess<br>
In [7]: x=subprocess.Popen(&#39;ls&#39;, stdout=subprocess.PIPE,<br>
stderr=subprocess.PIPE).communicate()<br>
In [10]: print x[0]<br>
...<br>
<br>
If you just want stdout and stderr of the subprocess to go to stdout and<br>
stderr of the calling process you can omit those arguments to Popen().<br>
<font color="#888888"><br>
Kent<br>
</font><div><div></div><div class="Wj3C7c">_______________________________________________<br>
Tutor maillist &nbsp;- &nbsp;<a href="mailto:Tutor@python.org">Tutor@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/tutor" target="_blank">http://mail.python.org/mailman/listinfo/tutor</a><br>
</div></div></blockquote></div><br>