summaryrefslogtreecommitdiffstats
path: root/rtemsspec/util.py
diff options
context:
space:
mode:
Diffstat (limited to 'rtemsspec/util.py')
-rw-r--r--rtemsspec/util.py36
1 files changed, 18 insertions, 18 deletions
diff --git a/rtemsspec/util.py b/rtemsspec/util.py
index bf07b5fa..e4c033db 100644
--- a/rtemsspec/util.py
+++ b/rtemsspec/util.py
@@ -78,21 +78,21 @@ def run_command(args: List[str],
exit status of the subprocess.
"""
logging.info("run in '%s': %s", cwd, " ".join(f"'{arg}'" for arg in args))
- task = subprocess.Popen(args,
- stdin=subprocess.PIPE,
- stdout=subprocess.PIPE,
- stderr=subprocess.STDOUT,
- cwd=cwd,
- env=env)
- assert task.stdout is not None
- while True:
- raw_line = task.stdout.readline()
- if raw_line:
- line = raw_line.decode("utf-8").rstrip()
- if stdout is None:
- logging.debug("%s", line)
- else:
- stdout.append(line)
- elif task.poll() is not None:
- break
- return task.wait()
+ with subprocess.Popen(args,
+ stdin=subprocess.PIPE,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT,
+ cwd=cwd,
+ env=env) as task:
+ assert task.stdout is not None
+ while True:
+ raw_line = task.stdout.readline()
+ if raw_line:
+ line = raw_line.decode("utf-8").rstrip()
+ if stdout is None:
+ logging.debug("%s", line)
+ else:
+ stdout.append(line)
+ elif task.poll() is not None:
+ break
+ return task.wait()