Answer the question
In order to leave comments, you need to log in
How to organize communication of processes through stdin/stdout?
My task is somewhat non-trivial, to organize communication between processes without sockets (only stdin / stdout).
The main script that runs the adjacent script:
import subprocess
messages = ['test1', 'test2', 'test3', 'test4', 'test5', ]
process = subprocess.Popen(['C:\\Python27\\python.exe', 'subscript.py'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True)
while len(messages)>0:
process.stdin.write(messages.pop() + '\n')
print process.stdout.readline()
import sys
while True:
print sys.stdin.readline()
Answer the question
In order to leave comments, you need to log in
Found a solution:
import subprocess
messages = ['test1', 'test2', 'test3', 'test4', 'test5', ]
process = subprocess.Popen(['C:\\Python27\\python.exe', 'subscript.py'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True)
while len(messages)>0:
process.stdin.write(messages.pop() + '\n')
process.stdin.flush()
print process.stdout.readline()
process.terminate()
import sys
while True:
sys.stdout.write(sys.stdin.readline())
sys.stdout.flush()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question