我正在做一个小项目来了解更多关于python 2.7的内容。 我做了一个关机定时器,我得到了所有的GUI设置,我只需要closuresWindows 8的命令。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))
两者都不起作用。 任何帮助表示赞赏,我使用Windows 8,所以我认为与Windows 7的解决scheme是不同的。
感谢您的答案,这里是我做的关机定时器:
https://github.com/hamiltino/shutdownTimer
subprocess.call
的第一个参数应该是程序参数(字符串)或单个字符串的序列。
尝试以下方法
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.
要么
import os time = 10 os.system("shutdown /t %s " % time) # `str` is not required, so removed.