python - Python 中是否有用于在 Windows 10 上即时关闭的命令?
问题描述
我想要一个可以立即关闭我的笔记本电脑的功能或命令。
我正在使用 Windows 10。
我希望代码如下:
command = input("what to do? ")
if command == "shutdown":
shutdown()
那应该关闭系统。
解决方案
是的,在窗户的情况下这很容易
windows内置shutdown /s /t0
了即时关机命令
代码:
import os
def shutdown():
#shutdown /s -> shuts down the computer [but it takes time]
#also shows message windows is going to be shutdown within a minute
#to avoid this we use /t parameter time=0seconds /t0
#command = shutdown /s /t0
#execute to the shell
os.system("shutdown /s /t0")
a = input("What to do?")
if a == "shutdown":
shutdown()
推荐阅读
- sql-server - 使用交叉应用的 SQL Server 字符串拆分返回错误
- python - 无法在 Flask 测试用例会话中检索数据库对象
- python - 如何将以下文本转换为 Pandas Dataframe?
- robotframework - 在机器人框架中我们可以使用元素应该在运行关键字中可见吗?
- networking - 为什么 cookie 只是签名而不是加密?
- json - Swift 使用参数初始化类,然后在没有参数的情况下对其进行初始化
- vue.js - 如果元素与 v-model 不匹配,则隐藏元素
- php - 函数 Main(CodeIgniter) 的参数太少
- angular - Angular 5 内容上传 GZip
- c# - 在 UWP C# 中从图像中获取主色