Suspend / Hibernate pc with python

后端 未结 7 1431
庸人自扰
庸人自扰 2021-01-19 02:01

I\'d like to write a short python script that puts my computer to sleep. I\'Ve already searched the API but the only result on suspend has to do with delayed execution. What

7条回答
  •  臣服心动
    2021-01-19 02:54

    I don't know how to sleep. But I know how to Hibernate (on Windows). Perhaps that is enough? shutdown.exe is your friend! Run it from the command prompt.

    To see its options do shutdown.exe /?

    I believe a hibernate call would be: shutdown.exe /h

    So, putting it all together in python:

    import os
    os.system("shutdown.exe /h")
    

    But as other have mentioned, it is bad to use os.system. Use the popen instead. But, if you're lazy like me and its a little script them meh! os.system it is for me.

提交回复
热议问题