How to send a new command to a subprocess
Earlier I asked a question about how to set up the tkinter gui to get strings from a subprocess without the whole program hanging. It is now functional.
Now I can't figure out how to send newlines to the subprocess. I tried using process.communicate, but I may have used it incorrectly. I also tried This question but self.process.stdin.write('stop\n'.encode())
doesn't seem to work. How to send new commands to python child subprocess?
Relevant code:
self.process = subprocess.Popen([ "python", "-u", dir + "start.py" ],
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
stderr=subprocess.PIPE,
cwd=dir)
+3
Mackenzie mcclane
source
to share
1 answer
Data can get stuck in the pipe. Add self.process.stdin.flush()
after recording.
+3
tdelaney
source
to share