Reputation: 31
Can anyone tell me how to add the shutdown.exe to python and how . i also want to set and variables like shutdown.exe -f -s -t 60
Upvotes: 3
Views: 5058
Reputation: 122890
The subprocess module allows you to run external programs from inside python. In particular subprocess.call is a really convenient way to run programs where you don't care about anything other than the return code:
import subprocess
subprocess.call(["shutdown.exe", "-f", "-s", "-t", "60"])
You can pass anything you want as part of the list so you could create a shutdown()
function like this:
import subprocess
def shutdown(how_long):
subprocess.call(["shutdown.exe", "-f", "-s", "-t", how_long])
So if we wanted to get user input directly from the console, we could do this:
dt = raw_input("shutdown> ")
dt = int(dt) #make sure dt is actually a number
dt = str(dt) #back into a string 'cause that's what subprocess.call expects
shutdown(dt)
Upvotes: 8