I am trying to use subprocess library.
The file that I am trying to run with subprocess:
a = input()
print(a)
Here is what I tried:
import subprocess
p = subprocess.Popen(['python', 'registration.py'], encoding="Utf8")
p.communicate(input="11")
It worked very well. Then I tried to use multiple inputs:
a=input()
print(a)
b=input()
print(b)
I used 2 p.communicate(input='something')
but got an error in the second one:
ValueError: I/O operation on closed file.
I surfed the Internet and found that communicate
only works once.
My question is, is there a way to give 2 inputs to subprocess in my case?
Here is the full code
import subprocess
from subprocess import PIPE
p = subprocess.Popen(['python', '-i', 'registration.py'], stdin=PIPE, text=True)
p.stdin.reconfigure(line_buffering=True)
p.stdin.write("phone_number\n")
#I should wait here for maximum 15 seconds
p.stdin.write("verification_code\n")
print("Done")
#First, Done is printed, console says program finished but then subprocess methods are executed