Reputation: 111
This is a follow up question to one that I posted earlier.
I have a html button that I would like to run a python script:
<form name = "input" action = "script.php" method = "get">
<input type= "submit" name = "submit" value="Submit" />
</form>
And the php it accesses looks like:
<?php exec("python /c/wamp/www/thursday.py");?>
My problem is that the code is not executing, and I am not receiving anything in my error log. What am I doing wrong?
My python code organizes images in a folder and asks for user input if the file is named incorrectly according to the way it organizes.
Will the python code still ask for input if it is run from a web server?
Sources I've looked at: Create HTML button to run Python Script and run python script with html button
Upvotes: 0
Views: 1489
Reputation: 387745
Will the python code still ask for input if it is run from a web server?
Yes and no. When the Python script is executed and it prompts for input, then yes, it will wait for input. However, it will not ask the user sitting in front of the browser for it; there’s just no way that this can happen. The Python script is executed on your server, by php, and the user just waits for the php script to return some response (HTML) that is then displayed.
If you want to pass information to the Python script, you should pass data from php via command line arguments or the standard input, and then read the script’s output to present it back to the user.
But it will be a lot cleaner, if you just stick to a single language there: Either put the logic into the php script, that way you can interact easily with the user via the webserver, or replace the whole php script by a Python web stack that does the same.
Upvotes: 3