0

.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.

  • This the real code? Because single quotes around `one` don't seem very useful. (And CMD usually expects double quotes or carets for escaping.) – mario May 20 '21 at 08:18
  • Yes this is the real code link prefer:- https://stackoverflow.com/questions/49015210/passing-php-variable-to-python-file and if I remove single quotes from $para1 it print same as before. – Mangal Prasad Hammad May 20 '21 at 08:40

1 Answers1

0

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