From 021b26973bf837153076669f7ee1c5e7d7a703f8 Mon Sep 17 00:00:00 2001 From: JustAnotherArchivist Date: Thu, 9 Mar 2023 10:45:22 +0000 Subject: [PATCH] Fix handling empty input --- codearchiver/subprocess.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/codearchiver/subprocess.py b/codearchiver/subprocess.py index 73d9339..453f7fc 100644 --- a/codearchiver/subprocess.py +++ b/codearchiver/subprocess.py @@ -20,17 +20,17 @@ def run_with_log(args, *, check = True, input = None, **kwargs): if badKwargs: raise ValueError(f'Disallowed kwargs: {", ".join(sorted(badKwargs))}') _logger.info(f'Running subprocess: {args!r}') - if input: + if input is not None: kwargs['stdin'] = subprocess.PIPE p = subprocess.Popen(args, **kwargs, stdout = subprocess.PIPE, stderr = subprocess.PIPE) sel = selectors.DefaultSelector() - if input: + if input is not None: sel.register(p.stdin, selectors.EVENT_WRITE) sel.register(p.stdout, selectors.EVENT_READ) sel.register(p.stderr, selectors.EVENT_READ) stdout = [] stderrBuf = b'' - if input: + if input is not None: stdinView = memoryview(input) stdinOffset = 0 PIPE_BUF = getattr(select, 'PIPE_BUF', 512) @@ -65,7 +65,7 @@ def run_with_log(args, *, check = True, input = None, **kwargs): if stderrBuf: _logger.info(stderrBuf.decode('utf-8')) assert p.poll() is not None - if input and stdinOffset < len(input): + if input is not None and stdinOffset < len(input): _logger.warning(f'Could not write all input to the stdin pipe (wanted to write {len(input)} bytes, only wrote {stdinOffset})') _logger.info(f'Process exited with status {p.returncode}') if check and p.returncode != 0: