如何使用计时器使用python 2.7关闭Windows 8

我正在做一个小项目,以了解有关python 2.7的更多信息.我正在制作一个关机计时器,我已经设置了所有GUI,我只需要关闭Windows 8的命令即可.cmd命令是:shutdown / t xxx.我尝试了以下方法:import subprocesstime = 1...

我正在做一个小项目,以了解有关python 2.7的更多信息.我正在制作一个关机计时器,我已经设置了所有GUI,我只需要关闭Windows 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的解决方案有所不同.

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

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.

本文标题为:如何使用计时器使用python 2.7关闭Windows 8

基础教程推荐