pythonlinuxbeagleboneblackpower-off

Power OFF the Beaglebone Black without Button or hardware intervention


I need to power OFF the Beaglebone black from a Python Code directly without using any gpio buttons or any hardware intervention.

There is the command line shutdown -h now but this command won't work on a python code since it requires a sudo password .... Any idea how can i interract with beaglebone black system ( linux command line without sudo ) in order to power off the board please ?

Thank you .


Solution

  • Well i tried this solution and it's working:

     from subprocess import Popen, PIPE
    
     sudo_password = 'temppwd'
     command = 'shutdown -h now'.split()
    
     p = Popen(['sudo', '-S'] + command, stdin=PIPE, stderr=PIPE,
                  universal_newlines=True)
    sudo_prompt = p.communicate(sudo_password + '\n')[1]