简体   繁体   中英

calling wrapper script in subprocess

I have a wrapperexec , which should call exec and a few arguments.

subprocess.check_call( ["wrapperexec", "exec", "arg1"], shell=True, cwd="/dirA" )

When I call above script it passes no arguments to wrapperexec . But when I change to:

subprocess.check_call( ["wrapperexec", "exec", "arg1"], shell=False, cwd="/dirA" )

it does pass arguments as expected. Could someone explain to me, why the former does not work?

EDIT:

Sorry, I was on the complete wrong track when creating this issue. Updated now to the real issue.

The environmental path is a complicated concept, there is the "base" path shared by everything, but you can also temporarily modify or append the path in specific processes. This means that if you modify the path in your script, but then call a subprocess , the subprocess will not have the same path as the parent script.

Unless you do the following:

subprocess.check_call(["nonsystemexec"], shell=True, cwd="/dirA", env=os.environ)

Here you are telling the subprocess to use your current env, which will include your current path .


Note: If you wanted to have the subprocess use a modified env, but not the same one you have. You can do something like this:

env = os.environ.copy()
env['PATH'] += ';/dirB'
subprocess.check_call(["nonsystemexec"], shell=True, cwd="/dirA", env=env)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM