在Python中是否有一个用于在Windows10上即时关闭的命令

我想要一个功能或命令,将立即关闭我的笔记本电脑。

我想要一个功能或命令,将立即关闭我的笔记本电脑。

我正在使用 Windows 10。

我希望代码是这样的:

command = input("what to do? ")
if command == "shutdown":
   shutdown()

这应该会关闭系统。

2

是的,在窗户的情况下很容易

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()
0

此功能应该工作:

import subprocess
import shlex
def shutdown():
    subprocess.run(shlex.split("shutdown /s"))

引用自https://its.uiowa.edu/support/article/109196

要关闭计算机,请键入 shutdown / s。
要重新启动计算机,请键入 shutdown / r。
要注销计算机,请键入 shutdown / l。
有关选项的完整列表,请键入 shutdown /?

本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处

(907)
Excel条件格式与空白和今天 ()
上一篇
请求 utl_http包时 Oracle错误“ORA-28759:无法打开文件”
下一篇

相关推荐

发表评论

登录 后才能评论

评论列表(3条)