0

I create a subprocess in python3.

p = subprocess.Popen('./a', stdin=subprocess.PIPE)

And I want to write to it stdin.

p.stdin.write('1\n')
do_something()
p.stdin.write('2\n')

But python only support write once. What should I do?
Should I use fcntl and how to use it?

qin
  • 1,627
  • 15
  • 22
  • Another option would be to use `communicate` as explained in [this question's first answer](https://stackoverflow.com/questions/8475290/how-do-i-write-to-a-python-subprocess-stdin). – Davy M Dec 10 '17 at 02:35
  • `communicate` can be called only once and it wait for subprocess. – qin Dec 10 '17 at 02:41
  • Should use `flush()` after `p.stdin.write()` – qin Dec 10 '17 at 02:48

0 Answers0