Rakesh_K Rakesh_K - 1 year ago 150
Python Question

subprocess.Popen process stdout returning empty?

I have this python code


saved as

in interactive shell

>>>from subprocess import Popen ,PIPE

>>> a.communicate()

(b'', None)


why it is not printing the

Answer Source

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

>>> a = Popen(['python3', 'ex1.py'], stdout=PIPE, stdin=PIPE)
>>> a.communicate(b'\n')
(b'spam\n', None)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download