0

I want to run python script from php. I am on python 3.5 , 64 bit .I have read StackQ1 and StackQ2. No one was helpful. I am running this code

<?php
$py = exec("D:/pythonFolder/python C:/wamp64/www/python.py");
echo $py;
?>

D:/pythonFolder/python is the path to python.exe. On running the above code, nothing happens. I also tried with this $py = shell_exec("python C:/wamp64/www/python.py"); and this $py = exec("python C:/wamp64/www/python.py"); but no success. Any help will be appreciative.

Community
  • 1
  • 1
Amar
  • 855
  • 5
  • 17
  • 36
  • Try adding a `$output` parameter to `exec` to check what is emitted. – SOFe Sep 17 '16 at 17:42
  • @PEMapModder Sorry. I am new in php. `$py` is already a output parameter. – Amar Sep 17 '16 at 17:46
  • Why would you expect any output from running `ls` on a Windows machine? And you're using `exec()` function wrong – ElefantPhace Sep 17 '16 at 18:01
  • Have you checked your command `D:/pythonFolder/python C:/wamp64/www/python.py` if it's working correctly on **cmd**?? Also `$py` will only have *The last line from the result of the command.* , you may want to check that as well. – leninhasda Sep 17 '16 at 18:13

1 Answers1

0

If you want to capture any output from the python script, you need to use shell_exec. Otherwise you're just running the script and the output isn't going anywhere. There are different commands for different purposes. Exec only runs a command, doesn't care about any potential return values.

http://php.net/manual/en/book.exec.php

Mike Mannakee
  • 361
  • 1
  • 5
  • I tried this, Nothing happens `$py = shell_exec("D:/pythonFolder/python C:/wamp64/www/python.py");` – Amar Sep 17 '16 at 17:44