I'm trying to run a program that requires successive interactions (I have to answer with strings: '0' or '1') from within my python script.
My code:
from subprocess import Popen, PIPE
command = ['program', '-arg1', 'path/file_to_arg1']
p = Popen(command, stdin=PIPE, stdout=PIPE)
p.communicate('0'.encode())
The last two lines work for the first interaction, but after that the program prints all the following questions on the screen without waiting for their respective inputs. I basically need to answer the first question, wait until the program deals with it and prints the second question, then answer the second question, and so on.
Any ideas? Thanks!
PS: I'm using Python 3.3.4