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?

6
  • 2
    Possible duplicate to this question Commented Feb 27, 2018 at 18:08
  • 1
    Why do you have quotes around shell_exec(? That prevents calling the function. Commented Feb 27, 2018 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...? Commented Feb 27, 2018 at 18:21
  • Possible duplicate of Execute python in a php script using shell_exec() Commented Feb 27, 2018 at 18:29
  • Possible duplicate of how do I pass many php variables to python Commented Feb 27, 2018 at 18:35

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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...?
Get rid of / before C:
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'");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.