Skip to content

Commit 9f073e3

Browse files
CopilotMLopez-Ibanez
authored andcommitted
* regtest.py (runcmd): merge the custom env with os.environ to preserve all environment variables including PATH. Default env is None.
1 parent a1fa50f commit 9f073e3

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

regtest.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,22 @@ def truncate_lines(output: str, max_lines: int) -> str:
112112
return "\n".join(lines[:max_lines] + ["...truncated"])
113113

114114

115-
def runcmd(command, cwd=None, env={}, outfile=subprocess.DEVNULL):
116-
env["LC_ALL"] = "C" # To avoid problems with sorting.
117-
env["ASAN_OPTIONS"] = ASAN_OPTIONS
118-
env["UBSAN_OPTIONS"] = UBSAN_OPTIONS
115+
def runcmd(command, cwd=None, env=None, outfile=subprocess.DEVNULL):
116+
# Merge with os.environ to preserve PATH and other environment variables
117+
full_env = os.environ.copy()
118+
if env is not None:
119+
full_env.update(env)
120+
full_env["LC_ALL"] = "C" # To avoid problems with sorting.
121+
full_env["ASAN_OPTIONS"] = ASAN_OPTIONS
122+
full_env["UBSAN_OPTIONS"] = UBSAN_OPTIONS
119123
stdout = outfile if outfile == subprocess.DEVNULL else subprocess.PIPE
120124
result = subprocess.run(
121-
command, shell=True, env=env, cwd=cwd, stdout=stdout, stderr=subprocess.STDOUT
125+
command,
126+
shell=True,
127+
env=full_env,
128+
cwd=cwd,
129+
stdout=stdout,
130+
stderr=subprocess.STDOUT,
122131
)
123132

124133
if stdout == subprocess.PIPE:

0 commit comments

Comments
 (0)