This repository was archived by the owner on May 25, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +53
-0
lines changed
projects/shutdown and reboot system Expand file tree Collapse file tree 2 files changed +53
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Script to shutdown and restart the system
2
+
3
+ - here the function is provided for both linux and windows.
4
+ - please comment the section which is not applicable for you (linux or windows)
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env python
2
+
3
+ import subprocess
4
+
5
+
6
+ #### For windows ####
7
+ def shutdown ():
8
+ instruction = "shutdown/s"
9
+ try :
10
+ output_response = subprocess .run (instruction , shell = True , capture_output = True )
11
+ print (output_response )
12
+ except Exception as e :
13
+ print (e )
14
+
15
+ def restart ():
16
+ instruction = "shutdown/r"
17
+ try :
18
+ output_response = subprocess .run (instruction , shell = True , capture_output = True )
19
+ print (output_response )
20
+ except Exception as e :
21
+ print (e )
22
+
23
+ """
24
+ ###### For Linux ######
25
+ def shutdown():
26
+ instruction = "sudo shutdown -r now"
27
+ try:
28
+ output_response = subprocess.run(instruction, shell=True, capture_output=True)
29
+ print(output_response)
30
+ except Exception as e:
31
+ print(e)
32
+
33
+ def restart():
34
+ instruction = "shudo reboot"
35
+ try:
36
+ output_response = subprocess.run(instruction, shell=True, capture_output=True)
37
+ print(output_response)
38
+ except Exception as e:
39
+ print(e)
40
+
41
+ """
42
+ if __name__ == '__main__' :
43
+ option = input ("Do you want to shutdown or restart [s/r]:" )
44
+ if option == 's' :
45
+ shutdown ()
46
+ elif option == 'r' :
47
+ restart ()
48
+ else :
49
+ print ("You want to continue using your pc! enjoy!" )
You can’t perform that action at this time.
0 commit comments