Search code examples
pythonphpxampplocalhostlocalserver

how do I get .php file variable to .py file


.php file code

<?php
$para1 = "one";
echo shell_exec("python C:/xampp/htdocs/python/test.py '$para1'");
?>

.py file code

#! C:\Users\mhammad\AppData\Local\Programs\Python\Python39\python.exe
print("Content-Type: text/html\n\r\n") #this code is for run .py file in xampp localserver.
import sys
print(sys.argv)

output of python file while running on xampp server in browser. ['C:/xampp/htdocs/python/test.py']

how do I get variable value from .php file to .py file.


Solution

  • This above mentioned code is working absolutely fine but the twist is that the xyz.py file is running in background on command line terminal and this print(sys.argv) can use the variable value $para1 = "one"; in xyz.py file and print the value of that shared variable. thanks