I'm not sure if this issue belongs here or on the python side, but hopefully someone can help me on this, and others can benefit here as well.
echo 1 | sudo tee /sys/class/backlight/rpi_backlight/bl_power > /dev/null echo 0 | sudo tee /sys/class/backlight/rpi_backlight/bl_power > /dev/null
as a working command-line entry to turn the backlight on and off from the pi user account.
sudo sh -c "echo 1 > /sys/class/backlight/rpi_backlight/bl_power" sudo sh -c "echo 0 > /sys/class/backlight/rpi_backlight/bl_power"
worked equally well.
Now, combining a
subprocess.Popen() method in python (referring to this page), I've tried
@staticmethod def screen_off(): command = "echo 1 | /usr/bin/sudo tee /sys/class/backlight/rpi_backlight/bl_power" process = subprocess.Popen(command.split(), stdout=subprocess.PIPE) output = process.communicate() print(output)
@staticmethod def screen_off(): commandarr = ["/usr/bin/sudo","/bin/sh","-c","\"echo 1 > /sys/class/backlight/rpi_backlight/bl_power\""] process = subprocess.Popen(commandarr, stdout=subprocess.PIPE) output = process.communicate() print(output)
to no avail; the former prints
b'1 | /usr/bin/sudo tee /sys/class/backlight/rpi_backlight/bl_power\n'
and the latter
/bin/sh: 1: echo 1 > /sys/class/backlight/rpi_backlight/bl_power: not found b''
the latter using the split() method gives
1: 1: 1: Syntax error: Unterminated quoted string b''
The shutdown counterpart works OK, so it probably isn't a user privilege issue...
The former is probably a problem using the pipe method, and the latter a problem with quotes and/or the sh -c parameter not going through...
Is there any way around these problems, or would I be better off writing a shell script and calling that instead?