Python Forum
passing php variable to python file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
passing php variable to python file
#1
I have a php file that pass file name as string variable to python. And once the python receive the string variable it will open the file based on the string variable.

python file
#!C:\Python\Python39\python.exe
print ('Content-type: text/html\n\n')
import sys
print(sys.argv)
filename = sys.argv[1]
print(filename)

with open(filename+'.py', 'r') as inFile:
  print(inFile.read())
php file
$filename = "stringfile";
$command = "python receivephpvariable.py  \"$filename\"";
echo $command ;
 echo shell_exec($command);
but i got the error :
Error:
['c:\\xampp\\htdocs\\project_real\\receivephpvariable.py'] Traceback (most recent call last): File "c:\xampp\htdocs\project_real\receivephpvariable.py", line 5, in <module> filename = sys.argv[1] IndexError: list index out of range
Reply
#2
I haven't used PHP for quite a while, but don't you need to index line 4 of the php to return first value?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Passing Openssl to Python 2.7 kromak 1 44 Apr-14-2026, 04:53 PM
Last Post: Larz60+
  How to write variable in a python file then import it in another python file? tatahuft 4 2,253 Jan-01-2025, 12:18 AM
Last Post: Skaperen
  Problems passing arguments containing spaces to bash script and then on to python kaustin 6 15,567 Apr-03-2024, 08:26 PM
Last Post: deanhystad
  Python Alteryx QS-Passing pandas dataframe column inside SQL query where condition sanky1990 0 2,202 Dec-04-2023, 09:48 PM
Last Post: sanky1990
  Passing flags to python script, through a function xbit 4 7,208 Apr-20-2021, 06:32 AM
Last Post: ndc85430
  Python reading variable in another py file wrongly _vertig0 2 3,466 Nov-21-2020, 07:19 AM
Last Post: _vertig0
  Passing List of Objects in Command Line Python usman 7 5,817 Sep-27-2020, 03:45 PM
Last Post: ndc85430
  passing variable to function Rejoice 4 4,456 Sep-11-2020, 03:27 AM
Last Post: Pleiades
  Python 2.7 passing variables from functions zetto33 1 2,964 Mar-19-2020, 07:27 PM
Last Post: Larz60+
  Passing variable to another function JonnyDriller 10 6,780 Feb-05-2020, 03:46 AM
Last Post: JonnyDriller

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020