bazzo54
Posts: 12
Joined: Thu Apr 11, 2013 8:46 am

comandi da Python

Sat Jun 09, 2018 4:47 pm

I need help !!

I looked online on my problem:

From the Python program commanded by a button on the Raspberry GPIO send a command directly of this type (sudo systemctl stop machine.service).

can you tell me how I can make it with Python ??

Thanks, Maurizio

User avatar
B.Goode
Posts: 10356
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: comandi da Python

Sat Jun 09, 2018 8:53 pm

There are many libraries and tutorials that assist with the task of reading the state of a button or switch attached to a gpio pin.

For example, the gpiozero Python library module Installed by default with the Raspbian Operating System has simple 'recipes' documented here: https://gpiozero.readthedocs.io/en/stab ... tml#button

To invoke a system shell command, one solution is the subprocess module: https://docs.python.org/3/library/subprocess.html

Return to “Python”