0

I am trying to invoke my python script from php by using passthru() function. I have already done that successfuly and for development I used xampp , now at some moment I installed manually apache,php and other add-ons. I also made changes to apache conf to make my python scripts work, some of them work when i invoke them directly via ajax,but scripts like this:

<?php

passthru("python C:/Apache24/htdocs/app1/pyscripts/export_zakup.py GARČIN
2>&1",$retval);
echo $retval;

?>

give me result like: 'python' is not recognized as an internal or external command, operable program or batch file. 1

Also when i copy python C:/Apache24/htdocs/app1/pyscripts/export_zakup.py GARČIN to my cmd it works properly. I have already spent few hours trying to find out where the problem is but unsuccessfuly. Anyone knows where the problem is?

Goran
  • 127
  • 1
  • 10

1 Answers1

1

First, locate where the Python executable is by runniing which python from the command line:

$ which python
$ /usr/bin/python

Then use the full path to the executable in your PHP script:

passthru("/usr/bin/python C:/Apache24/htdocs/app1/pyscripts/export_zakup.py GARČIN
2>&1",$retval);
echo $retval;

Keep in mind that the path will be different on Windows vs. Linux based machines. For example the latest versions on Windows typically install the executable in C:\Python27\, so the full path would be C:\Python27\python

Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119