Python Forum
Os.system("shutdown"); command not found
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Os.system("shutdown"); command not found
#1
Hi, I am trying to shutdown my Linux mint computer via a python script, but I get a command not found error.
os.system("shutdown now")
Error:
sh: line 1: shutdown: command not found
Reply
#2
Which user are you running this as? From memory, shutdown is typically only on root's path.
Reply
#3
Try
import subprocess
subprocess.run(['/sbin/shutdown', '-h', 'now'])
Reply
#4
(Nov-12-2022, 05:19 PM)Gribouillis Wrote: Try
import subprocess
subprocess.run(['/sbin/shutdown', '-h', 'now'])
Error:
Traceback (most recent call last): File "/home/cosmin/PycharmProjects/REMOTE-SHUTDOWN/main.py", line 2, in <module> subprocess.run(['/sbin/shutdown', '-h', 'now']) File "/usr/lib/python3.10/subprocess.py", line 501, in run with Popen(*popenargs, **kwargs) as process: File "/usr/lib/python3.10/subprocess.py", line 969, in __init__ self._execute_child(args, executable, preexec_fn, close_fds, File "/usr/lib/python3.10/subprocess.py", line 1845, in _execute_child raise child_exception_type(errno_num, err_msg, err_filename) FileNotFoundError: [Errno 2] No such file or directory: '/sbin/shutdown'
Reply
#5
So the problem was that I was running the python script via the Pycharm interpreter, so it worked when I ran it in the terminal.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Lightbulb shutdown host from docker container cosmin1805 0 961 Nov-27-2022, 06:34 PM
Last Post: cosmin1805
  Possible to execute a python script before log off/shutdown with input commands? Kaltex 1 2,282 May-18-2021, 06:31 AM
Last Post: Skaperen
  Difference between os.system("clear") and os.system("cls") chmsrohit 7 16,658 Jan-11-2021, 06:30 PM
Last Post: ykumar34
  How can I found how many numbers are there in a Collatz Sequence that I found? cananb 2 2,557 Nov-23-2020, 05:15 PM
Last Post: cananb
Question Difference between Python's os.system and Perl's system command Agile741 13 6,860 Dec-02-2019, 04:41 PM
Last Post: Agile741
  Detecting windows shutdown event riccardoob 4 5,739 Nov-12-2019, 04:51 PM
Last Post: Aurthor_King_of_the_Brittons
  Error executing Jupyter command 'notebook': [Errno 'jupyter-notebook' not found] 2 Newtopython123 10 31,347 Apr-25-2019, 07:30 AM
Last Post: banu0395
  run command on system with multi qoutes evilcode1 16 6,555 Aug-31-2018, 05:19 PM
Last Post: evilcode1
  pip command not found Able98 7 52,788 May-31-2017, 07:30 PM
Last Post: Able98
  System Command sushmita13 3 3,737 Apr-25-2017, 11:53 PM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020