[英]calling wrapper script in subprocess
I have a wrapperexec
, which should call exec
and a few arguments. 我有一个
wrapperexec
,应该调用exec
和一些参数。
subprocess.check_call( ["wrapperexec", "exec", "arg1"], shell=True, cwd="/dirA" )
When I call above script it passes no arguments to wrapperexec
. 当我调用上述脚本时,它不会将任何参数传递给
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. 环境
path
是一个复杂的概念,所有对象都共享“基本” path
,但是您也可以在特定过程中临时修改或附加该path
。 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. 这意味着,如果您修改脚本中的
path
,然后调用subprocess
,则该subprocess
将不会具有与父脚本相同的path
。
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
. 在这里,您告诉
subprocess
使用当前环境,其中将包括当前path
。
Note: If you wanted to have the subprocess
use a modified env, but not the same one you have. 注意:如果要让
subprocess
使用修改后的env,但不要使用相同的env。 You can do something like this: 您可以执行以下操作:
env = os.environ.copy()
env['PATH'] += ';/dirB'
subprocess.check_call(["nonsystemexec"], shell=True, cwd="/dirA", env=env)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.