Interaction with a continuously running subprocess

97 views Asked by At

Python 3.7

test.py

proc = subprocess.Popen(['python3.7', 'mirror.py'],
                        bufsize=0,
                        stdin=subprocess.PIPE,
                        stdout=subprocess.PIPE,
                        stderr=subprocess.STDOUT)

proc.stdin.write('1234\n'.encode())
proc.stdin.flush()
print(proc.stdout.read())

mirror.py

np = input()
print(np[::-1])

So I want to run mirror.py continuously and interract (send message to and reach ansver from) them more than one time. But when I try to add While True loop to mirror.py I got stuck: test.py not showing anything I try to change input and print to sys.stdin/out.read/write and got the same I try to change loop to multiply input/print pairs and got the same

I think I need to stop reading from stdout (maybe send something special from mirror.py after mirrored input) Can any one help me to reach the goal?

Thx

0

There are 0 answers