I know the trigger for on-board leds can be controlled from the command-line (or a script) I have a python program that I want to temporarily take over the system led blink it a little and return control to the trigger it had previously. I know I can read the current trigger by cat /sys/class/leds/led0/trigger and set it by echo mmc0 >/sys/class/leds/led0/trigger.

When I tried to do:


Nothing changed even though python did not complain (as long as it was started as root, which is another problem in itself).

Edit: I tried treating /sys/class/leds/led1/trigger like a regular ASCII file and opened it using sudo vi, erased the whole line with 'none' and it worked. Tried again and replaced the line with 'input' and it went back to its original trigger. So it seems like it can be treated like a regular text file. (I don't fully understand how it works just what it seems like)

I know that I can call:

os.system("echo input | sudo tee /sys/class/leds/led1/trigger > /dev/null")

However since the program is in python I was wondering if it can be controlled from within python without making a system call and how to do that.

  • The lines you list seem fine so far, it would be a good idea to close the file after the write. The files behave similar to regular files, that is the reason why you can use echo and cat. – RalfFriedl May 3 at 16:53
  • @RalfFriedl They are fine -except they don't work!- I would close the file after but that code is not being used because it does nothing. It seems that file is a little different than a regular file but I really don't know. – FoxSam12 May 3 at 19:47

Your Answer

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

Browse other questions tagged or ask your own question.