I want to use Popen from subprocess to execute the command: 'python3 test.py'
# The following is test.py code:
string = input('Enter Something')
if string == 'mypassword':
print('Success')
else:
print('Fail')
In my program, I want to execute 'python3 test.py' multiple times, each time supplying input, and reading the output ('Success' or 'Fail') and storing it in a variable.
My program that is suppose to execute 'python3 test.py' is as follows:
from subprocess import Popen, PIPE
# Runs test.py
command = Popen(['python3', 'test.py'], stdin=PIPE)
# After this, it prompts me to type in the input,
# but I want to supply it from a variable
# I want to do something like
my_input = 'testpassword'
command.supplyInput(my_input)
result = command.getOutput()
# result will have the string value of 'Success' or 'Fail'