0

i have a php file which have some variables para1 and para2 , i want to send them to a python file . this is my php file:

<?php

$para1 = "one";
$para2 = "two";
echo "shell_exec("
/C:/xampp/htdocs/Ai_Edutech_trial_project/eclipse_workspace/Project
/check.py '$para1' '$para2'")";
?>

and this is my py file:

import sys

x=sys.argv[1]
y=sys.argv[2]

print(x)
print(y)

but this does not work for me. Can someone please help me with this or suggest some other way?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
androfive
  • 3
  • 6
  • 2
    Possible duplicate to [this question](https://stackoverflow.com/questions/18721066/execute-python-in-a-php-script-using-shell-exec) – Zack Tarr Feb 27 '18 at 18:08
  • 1
    Why do you have quotes around `shell_exec(`? That prevents calling the function. – Barmar Feb 27 '18 at 18:11
  • ohh yes .. well i have tried that but it shows no output. is there any path argument error in function or anything else...? or should i use something other than print() in py...? – androfive Feb 27 '18 at 18:21
  • Possible duplicate of [Execute python in a php script using shell\_exec()](https://stackoverflow.com/questions/18721066/execute-python-in-a-php-script-using-shell-exec) – Necoras Feb 27 '18 at 18:29
  • Possible duplicate of [how do I pass many php variables to python](https://stackoverflow.com/questions/18451272/how-do-i-pass-many-php-variables-to-python) – ViG Feb 27 '18 at 18:35
  • Possible duplicate of [How to pass variable from PHP to Python?](https://stackoverflow.com/questions/12197815/how-to-pass-variable-from-php-to-python) – Scott Schupbach Feb 27 '18 at 18:38

2 Answers2

0

Don't put quotes around the function call. That turns it into a literal string, not a call to the function. Windows pathnames don't use a / before the drive letter, so the path should start with C:. And there shouldn't be a space after Project.

echo shell_exec("C:/xampp/htdocs/Ai_Edutech_trial_project/eclipse_workspace/Project/check.py '$para1' '$para2'");

Also, if you're just going to echo the result, you can use the passthru function instead.

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • ohh yes .. well i have tried that but it shows no output. is there any path argument error in function or anything else...? or should i use something other than print() in py...? – androfive Feb 27 '18 at 18:21
  • Get rid of `/` before `C:` – Barmar Feb 27 '18 at 18:33
0

I had a similar problem. Solved it by adding the word python in front of the path to the python script. As in:

echo shell_exec("python C:/xampp/htdocs/Ai_Edutech_trial_project/eclipse_workspace/Project/check.py '$para1' '$para2'");
lollalolla
  • 454
  • 5
  • 10