Reputation: 145
I want to execute python script with post data and get result from there using curl in php. If anyone have done this kind of functionality then please help. I have searched a lot but didn't get anything.
This is my python script path
cgi-bin/interactive.py
And i want to pass title=abc
as post data.
I have done it with shell_exec in php file,
$command = escapeshellcmd('cgi-bin/interactive.py test');
$output = shell_exec($command);
echo $output;
But in this i am facing issue with sys.argv
to fetch argument in python file.
Is it possible to pass argument with key=value with shell_exec? If yes then it can solve my problem otherwise i need to call with curl post data.
Thanks in advance!
Upvotes: 0
Views: 844
Reputation: 2443
To do advanced parsing of shell arguments you can use getopt or argparse modules. They are highly configurable and flexible.
Passing post data via shell arguments is, however, not proper as per the CGI spec (if this is supposed to be a true CGI application). Post data comes from stdin
in CGI, so in your Python program you can read in the HTTP response like regular user input, and then parse out the POST data. See this thread for more info.
Upvotes: 1