Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><code>stdout=None</code> means, the <code>stdout</code>-handle from the process is directly inherited from the parent, in easier words it basically means, it gets printed to the console (same applies for <code>stderr</code>).</p> <p>Then you have the option <code>stderr=STDOUT</code>, this redirects <code>stderr</code> to the <code>stdout</code>, which means the output of <code>stdout</code> and <code>stderr</code> are forwarded to the same file handle.</p> <p>If you set <code>stdout=PIPE</code>, Python will redirect the data from the process to a new file handle, which can be accessed through <code>p.stdout</code> (<code>p</code> beeing a <code>Popen</code> object). You would use this to capture the output of the process, or for the case of <code>stdin</code> to send data (constantly) to <code>stdin</code>. But mostly you want to use <code>p.communicate</code>, which allows you to send data to the process once (if you need to) and returns the complete <code>stderr</code> and <code>stdout</code> if the process is completed!</p> <p>One more interesting fact, you can pass any <code>file-object</code> to <code>stdin/stderr/stdout</code>, e.g. also a file opened with <code>open</code> (the object has to provide a <code>fileno()</code> method).</p> <p>To your <code>wait</code> problem. This should not be the case! As workaround you could use <code>p.poll()</code> to check if the process did exit! What is the return-value of the <code>wait</code> call?</p> <p><a href="http://docs.python.org/2/library/subprocess.html#frequently-used-arguments" rel="noreferrer">Furthermore, you should avoid <code>shell=True</code> especially if you pass user-input as first argument</a>, this could be used by a malicious user to exploit your program! Also it launches a shell process which means additional overhead. Of course there is the 1% of cases where you actually need <code>shell=True</code>, I can't judge this with your minimalistic example.</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