1

I want to pass a php variable to python script and then use it for execution in pyhton. Then I want to pass the result of the python script back to php file

Tried this :

test.php

<?php
   $param = 6;
   $result= shell_exec("python C:/xampp/htdocs/test/script.py $param");
   echo $result;
?>

and the python script

script.py

#!/usr/bin/env python
import sys

x = sys.argv[1]
print (x)
r = x + 5

print (r)

I'm getting a blank screen when I try to run test.php on browser meaning the variables are not being passed. I want to use the results from python script in php for further calculations.

I'm running both the codes on Windows interface.

3
  • Possible duplicate of How to pass variable from PHP to Python? Commented Feb 7, 2018 at 13:39
  • @xskxzr tried that, it's not working. Also I need to pass the variable value back to the php from python. Any other solutions? Commented Feb 7, 2018 at 13:48
  • Same issue here. How did you solve this ? I've solved almost everything. Commented Feb 7, 2020 at 22:01

0

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.