Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There could be two problems why you are not getting any output in stdout:</p> <ol> <li>The process is dumping all it's output to stderr.</li> <li>The system does not know how to execute <code>"imp -help"</code>.</li> </ol> <p>The solution for the first problem is easy: capture stderr using the argument <code>stderr = subprocess.PIPE</code>.</p> <p>The solution to the second is also easy, but the explanation is a bit longer: Subprocess does not guess much, it will just try to execute the whole string as one command. That means, in your case, it will try to execute <code>"imp -help"</code> as one command. It does not try to execute the command <code>"imp"</code> with the argument <code>"-help"</code>. You have to explicitly tell subprocess the command and the arguments separately.</p> <p>From the python <a href="http://docs.python.org/library/subprocess.html" rel="nofollow">documentation</a> on subprocess:</p> <blockquote> <p>args should be a string, or a sequence of program arguments. The program to execute is normally the first item in the args sequence or the string if a string is given, ...</p> </blockquote> <p>That means you have to separate the command and the arguments and pack them together in a sequence. This: <code>"imp -help"</code> should look like this: <code>["imp", "-help"]</code>. Read the <a href="http://docs.python.org/library/subprocess.html" rel="nofollow">documentation</a> on subprocess for more details on the intricacies of spliting the command and arguments.</p> <p>Here is how the code should look like:</p> <pre><code>import subprocess p=subprocess.Popen(["imp", "-help"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE) out,err=p.communicate() </code></pre> <p>Note: you also typed <code>p.communicate</code> instead of <code>p.communicate()</code>. I assume that was a typo in your question, not in your code.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload