【问题标题】:How can I shut down my computer using python script?如何使用 python 脚本关闭我的计算机?
【发布时间】:2019-02-12 11:39:27
【问题描述】:

我想为我编写的一些代码使用 python 脚本关闭我的计算机(mac)。我已经尝试了以下

os.system('shutdown -s')
os.system('shutdown -h now')

但是这两个都产生输出 256 并且我的系统没有关闭。

我读到这可能是由于没有 root 权限,但我想我无法通过 python 提供 root 权限。有没有办法可以运行 python 脚本并关闭我的 mac 并解决上述问题?

【问题讨论】:

标签: python


【解决方案1】:

重启:

re_start = ["shutdown", "-f", "-r", "-t", "30"]

关机:

 shut_down = ["shutdown", "-f", "-s", "-t", "30"]

因此:

def shutdown(self):
    import subprocess
    subprocess.call(shut_down)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-03-06
    • 2014-05-25
    • 1970-01-01
    • 2019-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多