我正在做一个小项目,以了解有关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


基础教程推荐
猜你喜欢
- 基于Python Dash库制作酷炫的可视化大屏 2023-08-04
- Linux安装python3.6 2023-09-03
- Python多处理比内核启动更多的进程 2023-11-11
- python--多线程--多进程--单元测试 2023-11-11
- python-从特定的内存地址读取数据/对对象的引用 2023-11-10
- [转] python numpy 导致多进程绑定同一个CPU问题解决方法 2023-09-03
- 基于Python编写一个自动关机程序 2023-08-11
- Python实现免费音乐下载器 2023-08-04
- 关于Python 列表的索引取值问题 2022-10-20
- 在Windows上安装Fabric(Python库)时出现“错误:找不到vcvarsall.bat” 2023-11-12