0

I have the following Python code (test.py) :

   name = input("What's your name? ")
   print("Nice to meet you " + name + "!")
   age = input("Your age? ")
   print("So, you are already " + str(age) + " years old, " + name + "!")

and I try to execute it with PHP :

exec('"C:\python.exe" test.py', $output);  
print_r($output);

But there are two input in the Python code. How can I sent the data asked by the input and continue the code execution ?

3
  • Use proc_open and use stdin pipe to pass data to the proccess. There's a few examples in the docs Commented Jun 20, 2017 at 13:47
  • Thanks apokryfos. But how can I do if the code change or if the number of input change. I try to make it works whatever the code is. Commented Jun 20, 2017 at 13:59
  • Automation like this is usually built ad-hoc. There's no generic solution available as far as I know. Commented Jun 20, 2017 at 14:10

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.