diff --git a/milatools/utils/local_v2.py b/milatools/utils/local_v2.py index d8fc1a74..06fbc2c3 100644 --- a/milatools/utils/local_v2.py +++ b/milatools/utils/local_v2.py @@ -184,7 +184,6 @@ async def run_async( subprocess.CalledProcessError If an error occurs when running the command and `warn` is `False`. """ - command_with_input = program_and_args + ((input,) if input else ()) logger.debug(f"Calling `asyncio.create_subprocess_exec` with {program_and_args=}") proc = await asyncio.create_subprocess_exec( @@ -195,17 +194,19 @@ async def run_async( start_new_session=False, ) if input: + # TODO: Getting a bug when sending 'echo $SCRATCH'! logger.debug(f"Sending {input=!r} to the subprocess' stdin.") - stdout, stderr = await proc.communicate(input.encode() if input else None) assert proc.returncode is not None if proc.returncode != 0: - logger.debug( - f"[{command_with_input!r}" + message = ( + f"{program_and_args!r}" + (f" with input {input!r}" if input else "") - + f" exited with {proc.returncode}]" + + f" exited with {proc.returncode}" + + (f": {stderr}" if stderr else "") ) + logger.debug(message) if not warn: if stderr: logger.error(stderr) @@ -216,11 +217,7 @@ async def run_async( stderr=stderr, ) if hide is not True: # don't warn if hide is True. - logger.warning( - RuntimeWarning( - f"Command {program_and_args!r} returned non-zero exit code {proc.returncode}: {stderr}" - ) - ) + logger.warning(RuntimeWarning(message)) result = subprocess.CompletedProcess( args=program_and_args, returncode=proc.returncode,