import subprocess
x = subprocess.Popen('/home/test/.local/share/somebinary arg1 arg2',
shell=True,
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
stderr=subprocess.PIPE)
x.stdin.write(b'user input')
x.communicate(input=b'\n')
I tried stdin.write
and communicate
but none of these things enter input in the process after executing initial command mentioned in Popen()
.
This is the output I get for above code:
$ python test.py
enter user input:
Process expects an input at this point and nothing happens until I manually write something or press enter.
Expected output:
$ python test.py
enter user input:user input
$
I tried the code from selected answer in How do I pass a string into subprocess.Popen (using the stdin argument)? and it does not resolve the issue. I get the same result.