Issue
I want a function or a command that will instantly shutdown my laptop.
I am using windows 10.
I want the code to be like:
command = input("what to do? ")
if command == "shutdown":
shutdown()
That should shut down the system.
Solution
Yeah that's easy in case of windows
windows has built in command shutdown /s /t0
for instant shutdown
Code:
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()
Answered By - Pear
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.