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 ?

Peter Estiven
  • 414
  • 1
  • 7
  • 16
  • Use [`proc_open`](http://php.net/manual/en/function.proc-open.php) and use stdin pipe to pass data to the proccess. There's a few examples in the docs – apokryfos Jun 20 '17 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. – Peter Estiven Jun 20 '17 at 13:59
  • Automation like this is usually built ad-hoc. There's no generic solution available as far as I know. – apokryfos Jun 20 '17 at 14:10

0 Answers0