0

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!

1

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

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.