Reputation: 392
I'm doing a small project to learn more about python 2.7. Im making a shutdown timer, I got the GUI all set up and I just need the command to shutdown windows 8. The cmd command is: shutdown /t xxx.
I have tried the following:
import subprocess
time = 10
subprocess.call(["shutdown.exe", "/t", "time"])
import os
time = 10
os.system("shutdown /t %s " %str(time))
Both don't work. Any help appreciated, I'm using Windows 8 so I think solutions with windows 7 are different.
Thanks for the answers, here is the shutdown timer i made:
https://github.com/hamiltino/shutdownTimer
Upvotes: 3
Views: 6666
Reputation: 369064
The first argument to the subprocess.call
should be the sequence of program arguments(strings) OR a single string.
Try following:
import subprocess
time = 10
subprocess.call(["shutdown.exe", "/t", str(time)]) # replaced `time` with `str(time)`
# OR subprocess.call([r"C:\Windows\system32\shutdown.exe", "/t", str(time)])
# specified the absolute path of the shutdown.exe
# The path may vary according to the installation.
or
import os
time = 10
os.system("shutdown /t %s " % time)
# `str` is not required, so removed.
Upvotes: 3