如何使用计时器关闭带有python 2.7的windows 8

如何使用计时器关闭带有python 2.7的windows 8,python,windows,python-2.7,Python,Windows,Python 2.7,我正在做一个小项目来进一步了解python 2.7。我正在做一个关机计时器,我已经把GUI都设置好了,我只需要命令就可以关闭Windows8。cmd命令是:shutdown/t xxx 我尝试了以下方法: import subprocess time = 10 subprocess.call(["shutdown.exe", "/t", "time"]) import os time = 10 os.system("shutdown /t %s " %str(time)) import s

我正在做一个小项目来进一步了解python 2.7。我正在做一个关机计时器,我已经把GUI都设置好了,我只需要命令就可以关闭Windows8。cmd命令是:shutdown/t xxx

我尝试了以下方法:

import subprocess
time = 10
subprocess.call(["shutdown.exe", "/t", "time"])


import os
time = 10
os.system("shutdown /t %s " %str(time))
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.
两者都不起作用。 感谢您的帮助,我使用的是Windows 8,所以我认为Windows 7的解决方案是不同的

感谢您的回答,这是我制作的关机计时器:

的第一个参数应该是程序参数序列(字符串)或单个字符串

请尝试以下操作:

import subprocess
time = 10
subprocess.call(["shutdown.exe", "/t", "time"])


import os
time = 10
os.system("shutdown /t %s " %str(time))
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.


每一个都会发生什么——错误消息、stacktrace,什么?我发现了,我需要添加/s。cmd用于弹出并消失,同时显示关机帮助菜单。