837
837
child, so you don't need to fix the environment after running.
839
839
env_changes = kwargs.get('env_changes', {})
840
843
def cleanup_environment():
841
844
for env_var, value in env_changes.iteritems():
842
old_val = osutils.set_or_unset_env(env_var, value)
845
old_env[env_var] = osutils.set_or_unset_env(env_var, value)
847
def restore_environment():
848
for env_var, value in old_env.iteritems():
849
osutils.set_or_unset_env(env_var, value)
844
851
bzr_path = os.path.dirname(os.path.dirname(bzrlib.__file__))+'/bzr'
845
852
args = list(args)
846
process = Popen([sys.executable, bzr_path]+args,
847
stdout=PIPE, stderr=PIPE,
848
preexec_fn=cleanup_environment)
855
# win32 subprocess doesn't support preexec_fn
856
# so we will avoid using it on all platforms, just to
857
# make sure the code path is used, and we don't break on win32
858
cleanup_environment()
859
process = Popen([sys.executable, bzr_path]+args,
860
stdout=PIPE, stderr=PIPE)
862
restore_environment()
849
864
out = process.stdout.read()
850
865
err = process.stderr.read()
851
866
retcode = process.wait()