subprocess.Popen process stdout returning empty?
<p>I have this python code</p>

<pre><code>input()
print('spam')
</code></pre>

<p>saved as <code>ex1.py</code></p>

<p>in interactive shell</p>

<pre><code>&gt;&gt;&gt;from subprocess import Popen ,PIPE
&gt;&gt;&gt;a=Popen(['python.exe','ex1.py'],stdout=PIPE,stdin=PIPE)

&gt;&gt;&gt; a.communicate()

(b'', None)

&gt;&gt;&gt;
</code></pre>

<p>why it is not printing the <code>spam</code></p>

<p>Input expects a whole line, but your input is empty. So there is only an exception written to <code>stderr</code> and nothing to <code>stdout</code>. At least provide a newline as input:</p>

<pre><code>&gt;&gt;&gt; a = Popen(['python3', 'ex1.py'], stdout=PIPE, stdin=PIPE)
&gt;&gt;&gt; a.communicate(b'\n')
(b'spam\n', None)
&gt;&gt;&gt; 
</code></pre>

python python-3.x subprocess