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

标签 python windows python-2.7

我正在做一个小项目来学习更多关于 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 - 如何使用计时器关闭带有 python 2.7 的 Windows 8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19094664/

相关文章:

c# - 如何在 Windows.Forms.PictureBox 中正确显示 Kinect 视频流?

python - 从 import 导入到 python 解释器主命名空间

python - zip 函数返回重复项

python - 从字符串中读取字节作为 float

python - 如何在树莓派上使用 crontab 运行代码

c# - 是否可以在 C# 中获取指定文件的资源管理器上下文菜单?

python - windows chrome 通过命令行刷新选项卡 0(或当前选项卡)

Python tkinter 在同一类中传递输入值

python - 编写脚本时在 python 2 和 3 版本之间切换

python - 基于第三列的 pandas 数据框颜色的 Seaborn 散点图