I've written a Python script which should eventually shutdown the computer.
This line is a part of it :
os.system("shutdown /p")
It makes some sort of a shutdown but remains on the turn-on Windows control pannel (where the user can switch the computer users).
Is there a way to fully shutdown the computer?
I've tried other os.system("shutdown ___")
methods with no success.
Is there another method which might help?
Summary. So this is how you can easily shutdown your system by using the Python programming language. The OS module in Python is a very useful tool as it can be used in many more tasks that are completely dependent on your system's operating system.
From the Start menu, open the Run dialog box or you can Press the "Window + R" key to open the RUN window. Type "shutdown -s -t <number in seconds>" and press Enter Key. For example, if you want to shut down your PC/laptop after 10 minutes then, type: shutdown -s -t 600.
You cannot restart a process in Python, instead you must create and start a new process with the same configuration.
import os
os.system('shutdown -s')
This will work for you.
For Linux:
import os
os.system('sudo shutdown now')
or: if you want immediate shutdown without sudo
prompt for password, use the following for Ubuntu and similar distro's:
os.system('systemctl poweroff')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With