我想要一个功能或命令,将立即关闭我的笔记本电脑。
我正在使用 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()
此功能应该工作:
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 /?
本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处
评论列表(3条)