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,2848 gold badges51 silver badges63 bronze badges
asked Feb 27, 2018 at 18:06
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.

answered Feb 27, 2018 at 18:13
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'");
answered Mar 10, 2020 at 16:36

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.