Ok so I have

sudo examplecommand
sudo examplecommand 2

I want to run any of these command blindly in the pi@raspberry terminal.

I never found a tutorial for it, only found tutorials for shut-down buttons and stuff similar to that, which all work via Python.

The best case scenario is where I power the Pi on and when I press 1 button sudo examplecommand runs and when I press another button sudo examplecommand2

The buttons could be from a keyboard or just from a button attached to a GPIO pin, (not GPIO 4 though)

How can I do this?


The console is not like a programming language, you cannot bind events to it, you can only type into a console. That is why its called a console.

One way to solve this problem is use something like a HID (Human Interface Device) emulator. Like barcode scanners, the just type out characters to the current cursor position. Not sure if that will work on a console though!? Security risk!!

You were on the right track with the Python. You need to write some software to listen to GPIO and then execute some code. It is really that simple. If you are new to programming, do not be scared to just get in and try write any kind of code. What is the worst that can happen? You will just learn how NOT to do it until eventually you get it working.

You can use a variety of programming languages on the Pi.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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