Issue
In the new asyncio framework, how do I write a drop-in async equivalent of subprocess.check_output to capture the full output of a process execution?
Solution
async def check_output(*args, **kwargs):
p = await asyncio.create_subprocess_exec(
*args,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
**kwargs,
)
stdout_data, stderr_data = await p.communicate()
if p.returncode == 0:
return stdout_data
A simple example solution (does not raise an error on failure, but instead returns None)
Answered By - Zachary Vance
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.