Pregunta

I'm making a program so that if the user enters a password in a python program incorrectly,it shuts down ubuntu. Example:

>password=input()
    >>if password=="ThePassword":
        >>>print ("Welcome")
    >>>>else:
        >>>>>(shutdown code here)

So if anyone can point me in the right direction, I would be very grateful.

By the way, I'm using Python 3.3 and running Ubuntu 13.10 64 bit

¿Fue útil?

Solución

What you want is to execute the shell command sudo shutdown -h now.

import subprocess
>password=input()
    >>if password=="ThePassword":
        >>>print ("Welcome")
    >>>>else:
        >>>>>subprocess.call(["sudo", "shutdown", "-h", "now"])

Most likely you will be prompted to enter your administrator password for this to work. You will need to run the program in sudo mode with root permissions.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top