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?
2 Answers 2
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.
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'");
shell_exec(? That prevents calling the function.