Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
782 views
in Technique[技术] by (71.8m points)

python - Sleep / Suspend / Hibernate Windows PC

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 function does the trick ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...