0

I am trying to write a function that calls a linux command that is given as a string.

I have

def run_command(self, command: str) -> None:
    subprocess.run(
                command.split(),
                text=True,
                stdout=subprocess.PIPE,
                check=True
    )

This seems to work with commands such as apt-get update

However when try LC_ALL=en_US.UTF-8 add-apt-repository -y ppa:ondrej/php I get

FileNotFoundError: [Errno 2] No such file or directory: 'LC_ALL=en_US.UTF-8'

What do I need to change to get this to work with any Linux command?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
matt
  • 1,817
  • 14
  • 35
  • In `var=value command arg1 arg2...`, the `var=value` is processed by the shell; one can't pass it to the operating system execv family of calls as an argument, but instead need to be adding it to the environment argument to execve (which is distinct from the argument-vector argument) when no shell is in use. The linked duplicate covers this. – Charles Duffy Nov 30 '22 at 21:49

0 Answers0