subprocess.call env var

19,202

You can use env with call in the exact same way as with popen:

subprocess.call(
    ["boto-rsync", "..."],
    env={"PATH":"/Library/Frameworks/Python.framework/Versions/2.7/bin/"},
    )
Share:
19,202
AliBZ
Author by

AliBZ

Updated on June 04, 2022

Comments

  • AliBZ
    AliBZ almost 2 years

    I'm using Popen because I need the env, like this:

    Popen(
        ["boto-rsync", "..."],
        env={"PATH":"/Library/Frameworks/Python.framework/Versions/2.7/bin/"},
        )
    

    The problem is Popen runs the command as a new thread. Is there any way that I could pass the env to subprocess.call or prevent Popen from creating a new thread? Thanx

  • AliBZ
    AliBZ almost 12 years
    Thanx, I don't know why I didn't try it ! I think I couldn't find the option.
  • Colin D Bennett
    Colin D Bennett about 10 years
    @AliBZ the documentation for subprocess.call is not clear on that point -- the only indication that other keyword args are supported is the tiny little asterisk in subprocess.call(args, *, stdin=None, stdout=None, stderr=None, shell=False)
  • jfs
    jfs over 8 years
    @AliBZ: to be clear: subprocess.call(cmd) is just subprocess.Popen(cmd).wait() i.e., you may pass to call() all arguments that you may pass to Popen().