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.

4
  • Try adding a $output parameter to exec to check what is emitted. Commented Sep 17, 2016 at 17:42
  • @PEMapModder Sorry. I am new in php. $py is already a output parameter. Commented Sep 17, 2016 at 17:46
  • Why would you expect any output from running ls on a Windows machine? And you're using exec() function wrong Commented Sep 17, 2016 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. Commented Sep 17, 2016 at 18:13

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

I tried this, Nothing happens $py = shell_exec("D:/pythonFolder/python C:/wamp64/www/python.py");

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.