diff --git a/archivebox/system.py b/archivebox/system.py index 1d8cbdb0..698c89f6 100644 --- a/archivebox/system.py +++ b/archivebox/system.py @@ -18,7 +18,7 @@ from .config import PYTHON_BINARY, OUTPUT_PERMISSIONS -def run(*args, input=None, capture_output=True, timeout=None, check=False, text=False, start_new_session=True, **kwargs): +def run(cmd, *args, input=None, capture_output=True, timeout=None, check=False, text=False, start_new_session=True, **kwargs): """Patched of subprocess.run to kill forked child subprocesses and fix blocking io making timeout=innefective Mostly copied from https://github.com/python/cpython/blob/master/Lib/subprocess.py """ @@ -37,10 +37,10 @@ def run(*args, input=None, capture_output=True, timeout=None, check=False, text= pgid = None try: - if args[0].endswith('.py'): - args = (PYTHON_BINARY, *args) + if isinstance(cmd, (list, tuple)) and cmd[0].endswith('.py'): + cmd = (PYTHON_BINARY, *cmd) - with Popen(*args, start_new_session=start_new_session, **kwargs) as process: + with Popen(cmd, *args, start_new_session=start_new_session, **kwargs) as process: pgid = os.getpgid(process.pid) try: stdout, stderr = process.communicate(input, timeout=timeout)