about summary refs log tree commit diff stats
path: root/archive/2024/winter/bsc_dichler/scripts/execution.py
diff options
context:
space:
mode:
authorMartin Fink <martin@finkmartin.com>2025-05-12 08:14:08 +0200
committerGitHub <noreply@github.com>2025-05-12 08:14:08 +0200
commit0866a557ac461a1b345dd9ff1e13b01105458ef8 (patch)
tree483f44335b623c1f2a8ba911d1feb776eb3df642 /archive/2024/winter/bsc_dichler/scripts/execution.py
parente546f71869e32e88716c4ad05e0254ea3352a668 (diff)
parentf60cf8c4ba75eee2b25ffbeea2330206b257aae9 (diff)
downloadresearch-work-archive-artifacts-0866a557ac461a1b345dd9ff1e13b01105458ef8.tar.gz
research-work-archive-artifacts-0866a557ac461a1b345dd9ff1e13b01105458ef8.zip
Merge pull request #2 from raphaeldichler/main
Add source code of 'Evaluation of the Performance of the Memory Tagging Extensions'
Diffstat (limited to 'archive/2024/winter/bsc_dichler/scripts/execution.py')
-rw-r--r--archive/2024/winter/bsc_dichler/scripts/execution.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/archive/2024/winter/bsc_dichler/scripts/execution.py b/archive/2024/winter/bsc_dichler/scripts/execution.py
new file mode 100644
index 000000000..51c1db4be
--- /dev/null
+++ b/archive/2024/winter/bsc_dichler/scripts/execution.py
@@ -0,0 +1,40 @@
+import asyncio
+from logging import info, error
+
+
+async def run(command: str | list[str], cwd: str | None = None) -> str:
+    if isinstance(command, list):
+        command = " && ".join(command)
+
+    command = command.strip()
+    assert command.startswith("&&") == False, "already prefixed with '&&'"
+
+    info(command)
+    cp = await asyncio.create_subprocess_shell(
+        cmd=command,
+        stdout=asyncio.subprocess.PIPE,
+        stderr=asyncio.subprocess.PIPE,
+        cwd=cwd,
+    )
+
+    async def read_stream(stream, logger):
+        lines = ""
+        while True:
+            line = await stream.readline()
+            if not line:
+                return lines
+            line = line.decode().strip()
+            lines += line
+            logger(line)
+
+    output: tuple[str, str] = await asyncio.gather(
+        read_stream(cp.stdout, info),
+        read_stream(cp.stderr, error),
+    )
+
+    _ = await cp.wait()
+    if cp.returncode == 1:
+        error("Failed.")
+        exit(1)
+
+    return output[0]