Calling a Python Script from PHP

Hemant Pandey

I am trying to call a python script from my PHP page but no output is being delivered. Is there any error in code ?

<?php
include('main.php'); 
$lat = $_POST['lt'];
$lon = $_POST['ln'];
$uid = $_POST['id'];
$rad = $_POST['rd'];

$outs = 'python recommend.py ' . $uid . ' ' . $lat . ' ' . $lon . ' ' .     $rad;
$output = shell_exec($outs);
echo $output;
?>

Whereas I tried to get the output using dummy variables, it is being shown.

<?php
$lat = $_POST['lt'];
$lon = $_POST['ln'];
$uid = $_POST['id'];
$rad = $_POST['rd'];
echo        "11,28.720663,77.106192,1.18764869157,50.2058551405~12,28.705344,77.147270,2.854    76982119,2.42050298022~14,28.697590,77.143108,2.63211107261,13.1314821232~64,28.        683058,77.079048,2.10283926574,28.9526789043~66,28.670294,77.126684,2.8317092358    ,5.80484607006~67,28.677712,77.092713,1.95077211146,28.4871314757~68,28.665512,7    7.093081,2.76955528898,21.8407451837~71,28.674069,77.124547,2.53467055409,24.755    4907651~"
?>
Pedro Lobito

My guess is that you need to provide the full path to the python script, i.e.:

python /full/path/to/recommend.py

As mentioned on my comments, in order to properly debug php, you'll need to enable error reporting at the top of your php scripts , i.e.:

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
//the rest of your code...

Comment on production mode.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Calling a shell script from python

From Dev

calling python script from another script

From Dev

Calling a Google App Script from PHP?

From Dev

Calling Python script from Matlab with arguments

From Dev

Calling Scrapy Spider from python script?

From Dev

calling hive -e from a python script

From Dev

Calling Python script with arguments from VBscript

From Dev

Calling python function from shell script

From Dev

Calling alias Command from python script

From Dev

Calling a local python script from javascript

From Dev

Change directory from python script for calling shell

From Dev

Calling python script with parameters from tcl

From Dev

Python script calling PHP script while passing $_GET parameters

From Dev

Python script calling PHP script while passing $_GET parameters

From Dev

python calling variables from another script into current script

From Dev

Calling PHP script with Cordova

From Dev

Calling Python file from within PHP

From Dev

Calling python script from c#, unexpected token 'from' error

From Java

Running a Python script from PHP

From Dev

Execute Python script from Php

From Dev

Execution of a Python Script from PHP

From Dev

Calling node.js script from PHP returns nothing

From Dev

php calling variables from another script to assign for the session

From Dev

Python ImportError when calling Python script from Java

From Dev

Python ImportError when calling Python script from Java

From Dev

ImportError: No module named xmltodict while calling from other Python script

From Dev

calling python script that requires an input from within bash for loop

From Dev

Calling a Python script from Javascript, both local files

From Dev

Calling R script from python using rpy2

Related Related

  1. 1

    Calling a shell script from python

  2. 2

    calling python script from another script

  3. 3

    Calling a Google App Script from PHP?

  4. 4

    Calling Python script from Matlab with arguments

  5. 5

    Calling Scrapy Spider from python script?

  6. 6

    calling hive -e from a python script

  7. 7

    Calling Python script with arguments from VBscript

  8. 8

    Calling python function from shell script

  9. 9

    Calling alias Command from python script

  10. 10

    Calling a local python script from javascript

  11. 11

    Change directory from python script for calling shell

  12. 12

    Calling python script with parameters from tcl

  13. 13

    Python script calling PHP script while passing $_GET parameters

  14. 14

    Python script calling PHP script while passing $_GET parameters

  15. 15

    python calling variables from another script into current script

  16. 16

    Calling PHP script with Cordova

  17. 17

    Calling Python file from within PHP

  18. 18

    Calling python script from c#, unexpected token 'from' error

  19. 19

    Running a Python script from PHP

  20. 20

    Execute Python script from Php

  21. 21

    Execution of a Python Script from PHP

  22. 22

    Calling node.js script from PHP returns nothing

  23. 23

    php calling variables from another script to assign for the session

  24. 24

    Python ImportError when calling Python script from Java

  25. 25

    Python ImportError when calling Python script from Java

  26. 26

    ImportError: No module named xmltodict while calling from other Python script

  27. 27

    calling python script that requires an input from within bash for loop

  28. 28

    Calling a Python script from Javascript, both local files

  29. 29

    Calling R script from python using rpy2

HotTag

Archive