views:

79

answers:

2

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

+7  A: 

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"])

Update:

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)
Aaron Maenpaa
how can i add a user input instead of the number 60??
geocheats2
you just use a variable? ensure that it's a number casting it to int, or you'll have very unpleasant consequences.
Lo'oris
A: 

how can i add a user input instead of the number 60??

geocheats2
You should delete this answer and just leave your comment.
Aaron Maenpaa