0

I want to shut down my computer(mac) using a python script for some code I have written. I have tried the following

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

But both of these produce the output 256 and my system doesn't shut down.

I read it might be due to not having root privileges but I guess I can't provide root privileges through python. Is there a way I can run a python script and shut down my mac with the above problem ?

1

1 Answer 1

1

For restart:

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

For shutdown:

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

Hence:

def shutdown(self):
    import subprocess
    subprocess.call(shut_down)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.