1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-12-23 23:38:21 +00:00

Use proc.communicate() when checking for subprocess output

As recommended in https://docs.python.org/3/library/asyncio-subprocess.html#asyncio.subprocess.Process.stderr
This commit is contained in:
grossmj 2023-05-14 13:58:50 +08:00
parent b4bfb24a80
commit af2fc8c111

View File

@ -71,10 +71,10 @@ async def subprocess_check_output(*args, cwd=None, env=None, stderr=False):
if stderr:
proc = await asyncio.create_subprocess_exec(*args, stderr=asyncio.subprocess.PIPE, cwd=cwd, env=env)
output = await proc.stderr.read()
_, output = await proc.communicate()
else:
proc = await asyncio.create_subprocess_exec(*args, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.DEVNULL, cwd=cwd, env=env)
output = await proc.stdout.read()
output, _ = await proc.communicate()
if output is None:
return ""
# If we received garbage we ignore invalid characters