[Python] Python subprocess/Popen with a modified environment

Discussão em 'Python' iniciado por Stack, Março 4, 2025.

  1. Stack

    Stack Membro Participativo

    I believe that running an external command with a slightly modified environment is a very common case. That's how I tend to do it:

    import subprocess, os
    my_env = os.environ
    my_env["PATH"] = "/usr/sbin:/sbin:" + my_env["PATH"]
    subprocess.Popen(my_command, env=my_env)


    I've got a gut feeling that there's a better way; does it look alright?

    Continue reading...

Compartilhe esta Página