Meta: Only kill child process in run_command() if it is bound

Scoping here was backwards, causing 'process' to be possibly used while
unbound.
This commit is contained in:
Zaggy1024 2026-04-29 21:31:26 -05:00 committed by Gregory Bertilson
parent 675e209f5e
commit d89e9bb44d

View file

@ -21,9 +21,9 @@ def run_command(
stdin = subprocess.PIPE if type(input) is str else None
stdout = subprocess.PIPE if return_output else None
try:
# FIXME: For Windows, set the working directory so DLLs are found.
with subprocess.Popen(command, stdin=stdin, stdout=stdout, text=True, cwd=cwd) as process:
# FIXME: For Windows, set the working directory so DLLs are found.
with subprocess.Popen(command, stdin=stdin, stdout=stdout, text=True, cwd=cwd) as process:
try:
(output, _) = process.communicate(input=input)
if process.returncode != 0:
@ -31,11 +31,11 @@ def run_command(
sys.exit(process.returncode)
return None
except KeyboardInterrupt:
process.send_signal(signal.SIGINT)
process.wait()
except KeyboardInterrupt:
process.send_signal(signal.SIGINT)
process.wait()
sys.exit(process.returncode)
sys.exit(process.returncode)
if return_output:
return output.strip()