1
0
Fork 0
mirror of synced 2024-05-06 21:52:30 +12:00

Use asyncio's subprocess module

This commit is contained in:
Dan Hess 2020-04-13 14:15:37 -05:00
parent 86546dec16
commit 04c029b368

View file

@ -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):