The subprocess module allows you to run external programs from within python. In particular, subprocess.call is a really convenient way to run programs where you donβt care about anything except the return code:
import subprocess
subprocess.call(["shutdown.exe", "-f", "-s", "-t", "60"])
Update:
You can pass whatever you want as part of a list to create a function shutdown()as follows:
import subprocess
def shutdown(how_long):
subprocess.call(["shutdown.exe", "-f", "-s", "-t", how_long])
So, if we want to get user input directly from the console, we can do this:
dt = raw_input("shutdown> ")
dt = int(dt)
dt = str(dt)
shutdown(dt)
source
share