Use asyncio's subprocess module
This commit is contained in:
parent
86546dec16
commit
04c029b368
|
@ -188,11 +188,16 @@ class Owner(commands.Cog):
|
||||||
@commands.command()
|
@commands.command()
|
||||||
async def bash(self, ctx, *, cmd: str):
|
async def bash(self, ctx, *, cmd: str):
|
||||||
"""Runs a bash command"""
|
"""Runs a bash command"""
|
||||||
output = subprocess.check_output("{}; exit 0".format(cmd), stderr=subprocess.STDOUT, shell=True)
|
proc = await asyncio.create_subprocess_shell(
|
||||||
if output:
|
cmd,
|
||||||
await ctx.send("```\n{}\n```".format(output.decode("utf-8", "ignore").strip()))
|
stdout=asyncio.subprocess.PIPE,
|
||||||
|
stderr=asyncio.subprocess.STDOUT
|
||||||
|
)
|
||||||
|
stdout = (await proc.communicate())[0]
|
||||||
|
if stdout:
|
||||||
|
await ctx.send(f'[stdout]\n{stdout.decode()}')
|
||||||
else:
|
else:
|
||||||
await ctx.send("No output for `{}`".format(cmd))
|
await ctx.send("Process finished, no output")
|
||||||
|
|
||||||
@commands.command()
|
@commands.command()
|
||||||
async def shutdown(self, ctx):
|
async def shutdown(self, ctx):
|
||||||
|
|
Loading…
Reference in a new issue