[英]How can I shut down my computer using python script?
I want to shut down my computer(mac) using a python script for some code I have written. 我想使用python脚本关闭我的计算机(mac),以获取我编写的某些代码。 I have tried the following
我尝试了以下
os.system('shutdown -s')
os.system('shutdown -h now')
But both of these produce the output 256 and my system doesn't shut down. 但是这两个都产生输出256,而我的系统没有关闭。
I read it might be due to not having root privileges but I guess I can't provide root privileges through python. 我读到它可能是由于没有root特权,但我想我无法通过python提供root特权。 Is there a way I can run a python script and shut down my mac with the above problem ?
有没有一种方法可以运行python脚本并关闭上述问题的Mac?
For restart: 重新启动:
re_start = ["shutdown", "-f", "-r", "-t", "30"]
For shutdown: 对于关机:
shut_down = ["shutdown", "-f", "-s", "-t", "30"]
Hence: 因此:
def shutdown(self):
import subprocess
subprocess.call(shut_down)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.