we ara planning to make a program for raspberry pi 3. We figured out that maybe it would be better to write this program as a website with python.

If the button is a website element, and the website using python, can i control linux functions thru website on raspberry?

This is a user dashboard with several functions like media library, google maps integration, google places near and so on.

  • Are you trying to make a website using python?
    – user67191
    Commented Jun 25, 2017 at 10:31
  • Html, css, python. I could use php but i hope if i am using python i can control raspberry and/or linux functions
    – Ignity
    Commented Jun 25, 2017 at 10:40
  • You can also launch system commands in PHP, using proc_open(), or system(). Jacobm001's warning still applies ;) Commented Jun 25, 2017 at 20:37

2 Answers 2


If the button is a website element, and the website using python, can i control linux functions thru website on raspberry?

Yes, basically you can do this with these python functions : os.system("someapp.sh") (launch a task),commands.getstatus("someapp.sh") (launch & read exit status code) or commands.getstatusoutput("someapp.sh") (launch and read both return code and result as a string)

You can also play with subprocess, reading and feeding application in real time with subprocess.Popen(["someapp.sh"], stdout=PIPE)

  • Thank you for your answer. It works similar to javascript? So by pushing an anchor i can call the script?
    – Ignity
    Commented Jun 25, 2017 at 11:07
  • Web programmation often involve multiple langages. i.e. PHP read data from SQL, in order to generate both HTML (for the browser can display pages) and javascript (for managing user interaction). In your case, python will only be able to replace the PHP part. You will probably still need to use javascript for managing user event, on the user side. But yes, you will be able to have your python code executed when the user click a <a src="somepage.py"> link, once your webserver have python linked to it : docs.python.org/2/howto/webservers.html Commented Jun 25, 2017 at 13:35

The great thing about programming is that you can do pretty much whatever you want to do if you have the right level of knowledge. What you're talking about has two primary components.

  1. A webpage. This will probably be written in HTML/CSS with a little Javascript for asynchronous functionality.

  2. A python backend that accepts commands and then does things to your RPi. I would suggest you look into python's Flask API for this.


You need to be very careful about running a webpage that includes system manipulation. Make sure you're familiar with the concept of injection attacks. Python is slightly safer in this regard than SQL, but be extremely wary of any input that comes from user space. Just because your website doesn't have the option, doesn't mean they can't access a public API directly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.