From 04c029b368b178cc6c2bd9acb436d9352ae1e942 Mon Sep 17 00:00:00 2001 From: Dan Hess Date: Mon, 13 Apr 2020 14:15:37 -0500 Subject: [PATCH] Use asyncio's subprocess module --- cogs/owner.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/cogs/owner.py b/cogs/owner.py index 741bb9b..71475ec 100644 --- a/cogs/owner.py +++ b/cogs/owner.py @@ -188,11 +188,16 @@ class Owner(commands.Cog): @commands.command() async def bash(self, ctx, *, cmd: str): """Runs a bash command""" - output = subprocess.check_output("{}; exit 0".format(cmd), stderr=subprocess.STDOUT, shell=True) - if output: - await ctx.send("```\n{}\n```".format(output.decode("utf-8", "ignore").strip())) + proc = await asyncio.create_subprocess_shell( + cmd, + stdout=asyncio.subprocess.PIPE, + stderr=asyncio.subprocess.STDOUT + ) + stdout = (await proc.communicate())[0] + if stdout: + await ctx.send(f'[stdout]\n{stdout.decode()}') else: - await ctx.send("No output for `{}`".format(cmd)) + await ctx.send("Process finished, no output") @commands.command() async def shutdown(self, ctx):