sp.py file:
#!/usr/bin/env python3 s = input('Waiting for your input:') print('Data:' + s)
file main.py
import subprocess as sp pobj = sp.Popen('sp.py',stdin=sp.PIPE,stdout=sp.PIPE,shell=True) print(pobj.stdout.read().decode()) pobj.stdin.write(b'something...') print(pobj.stdout.read().decode())
main.py will be blocked in the first pobj.stdout.read() , because sp.py is waiting for me.
But if I want to process the line "Waiting for input": first, how can I find out if sp.py is waiting for me?
In other words, I want pobj.stdout.read() return when sp.py was waiting (or sleeping because of time.sleep() ).
source share