/    Sign up×
Community /Pin to ProfileBookmark

Can we run a python script by clicking a button from HTML or PHP

Hey, I want to know that can we trigger a python script by clicking a form submit button on the HTML page so that the form values can be transferred to python script ?

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@NogDogDec 06.2020 — Yes.

The details will depend on whether you have that Python script available in some sort of web app API that you can directly call via HTTP. If not, you have have to do something clunky like calling a PHP script that uses shell_exec() perhaps to call that Python script in command line mode, capture the results, then return it to them browser.
Copy linkTweet thisAlerts:
@saireddy-1authorDec 07.2020 — @NogDog#1625659 could you help me in briefing that any sort of resources will be helpful
Copy linkTweet thisAlerts:
@SeverussMay 19.2021 — In PHP, the 'shell_exec' function can be used. It can be executed via the shell and the result can be returned as a string. It returns an error if NULL is passed from the command line or returns no output at all.
Copy linkTweet thisAlerts:
@johncarryMay 19.2021 — You have to use **Php** to make a command line call to run your **python script**. There is an "exec" function in **php** which is used for executing command line operations. So, you have to write the following command in your button click operation: exec('python filename.py')
Copy linkTweet thisAlerts:
@Alberto322May 19.2021 — Any ideas why the exec might not work?
Copy linkTweet thisAlerts:
@SeverussMay 19.2021 — Does it differ by the python version you use, I mean can that have any effect? I've just started taking p[ython coding classes](https://nurtem.com/classes-and-camps/programming/python), so it's true that there might be other errors in my code that prevent it from running. Though I have to admit and pride myself a little, I'm surprised at how fast I've learned with the coding classes, I expected it to just provide me the basic knowledge about python, but apparently, I've already got so much more. If there is someone that can take a look at my code, let me know, please.
×

Success!

Help @saireddy-1 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...