-2

I have a php script with a text form and a button.on clicking the button the data entered in textform is stored in the phpmyadmin db.i am using xampp for php. another python script is linked to this same table in db taking the text from the table and generating the response.

I want the python script to be called automatically every time after the user has entered the text and clicked the button.how shall I execute this problem and how to run the python script in xampp as I saw some answers but was confused on the use of exec () calls and other methods.. Using python 3.4 Detailed steps explanation is appreciated. Python directory:c:\python34 .py file directory:c:\xampp\htdocs .php file directory; c:\xampp\htdocs

Please somebody help..

Abhi
  • 1
  • 2
  • did you install python on xampp so that you can run a script on localhost? if yes, calling the script by it's url should be enough, by any method you choose in PHP. If not, see [the answer here](https://stackoverflow.com/questions/42704846/running-python-scripts-with-xampp) – Kaddath Feb 26 '18 at 08:24
  • Hey mate.i setup python on xampp as per the above steps and worked fine.could you tell me the correct way to write the exec () statement..and should I use exec () or shell_exec ()..which is suited for windows – Abhi Feb 26 '18 at 13:23
  • I tried to use exec but it simply gives no output – Abhi Feb 26 '18 at 13:26
  • i don't understand, why do you want to use `exec` with this setup? The goal for making python scripts executable in xampp is that your server executes them when you serve the scripts, from now you can even do a redirection to a `localhost/folder/script.py` it should work. So basically if you don't want to redirect but just call the script and have a reponse, use functions like `$response = file_get_contents('folder/script.py');` rather. `exec` is when your server cannot execute the python scripts and that you have to call the python executable yourself. – Kaddath Feb 26 '18 at 14:11
  • I actually wanted to run the python script every time a button is pressed.i used exec() and now it runs the python script from the php.. – Abhi Feb 27 '18 at 05:53
  • Thanks for your help...u really saved me..I have been managing this problem for last 2 days..now it runs – Abhi Feb 27 '18 at 05:54

1 Answers1

0

Firstly, try to make python scripts run in the xampp ..for that change the settings in the httpd.conf file as given in other posts...

Once u get running python scripts in xampp..try to run the python script from browser localhost/xyz.py. and if you get the output then this means xampp can now run python files.

Then in your php script just call exec () function to execute the python script..this one line does wonders.

Abhi
  • 1
  • 2