1

I'm trying to run this code:

import subprocess
def install_curl():
    result = subprocess.check_output(['command', '-v', 'dnf']) # 
    if not result:
        print("You should Install curl")
    else:
        result = subprocess.check_output(['command', '-v', 'apt'])
        print(result)
install_curl()

Then I'm getting this error:

Traceback (most recent call last):
  File "/home/pbravodez1/projects/Automate_task/test_gpg.py", line 98, in <module>
    install_curl()
  File "/home/pbravodez1/projects/Automate_task/test_gpg.py", line 91, in install_curl
    result = subprocess.check_output(['command', '-v', 'dnf']) # 
  File "/usr/lib/python3.8/subprocess.py", line 411, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "/usr/lib/python3.8/subprocess.py", line 489, in run
    with Popen(*popenargs, **kwargs) as process:
  File "/usr/lib/python3.8/subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.8/subprocess.py", line 1702, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'command'

Do you have any idea on how to run this "command" in order to check which package manager is installed in the Operating System?

5
  • Please format (indent) your python code properly Commented Aug 19, 2020 at 13:31
  • Thanks @JanStránský but it seems that when I was writing this question turns like that. My code is well indented on my side. Commented Aug 19, 2020 at 18:55
  • Have a look at this SO question Commented Aug 20, 2020 at 8:35
  • Seems like command is a BASH-specific, not available in Python (similar to BASH aliases defined in .bashrc file) Commented Aug 20, 2020 at 8:41
  • Thanks again @JanStránský and yes seems like. I was trying to make it in a nice and short way. I will take a look at the link you suggested. Commented Aug 20, 2020 at 20:46

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.