Skip to content

Commit 08f1f79

Browse files
committed
auto-clean: improve subprocess handling
1 parent fd9cdc6 commit 08f1f79

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

crytic_compile/utils/subprocess.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Utils for running executables across platforms
2+
Process execution helpers.
33
"""
44
import logging
55
import os
@@ -46,10 +46,23 @@ def run(
4646

4747
try:
4848
return subprocess.run(
49-
cmd, executable=subprocess_exe, cwd=subprocess_cwd, env=subprocess_env, check=True, **kwargs
49+
cmd,
50+
executable=subprocess_exe,
51+
cwd=subprocess_cwd,
52+
env=subprocess_env,
53+
check=True,
54+
capture_output=True,
55+
**kwargs,
5056
)
5157
except FileNotFoundError:
5258
LOGGER.error("Could not execute `%s`, is it installed and in PATH?", cmd[0])
59+
except subprocess.CalledProcessError as e:
60+
LOGGER.error("'%s' returned non-zero exit code %d", cmd[0], e.returncode)
61+
stdout, stderr = (e.stdout.decode().strip(), e.stderr.decode().strip())
62+
if stdout:
63+
LOGGER.error("\nstdout: ".join(stdout.split("\n")))
64+
if stderr:
65+
LOGGER.error("\nstderr: ".join(stderr.split("\n")))
5366
except OSError:
5467
LOGGER.error("OS error executing:", exc_info=True)
5568

0 commit comments

Comments
 (0)