import asyncio
import sys
import subprocess
from asyncio.subprocess import PIPE
class main:
def __init__(self):
self.proc = None
def get_proc(self):
return self.proc
async def run(self, cmd):
new_cmd = 'stdbuf -oL ' + cmd
self.proc = await asyncio.create_subprocess_shell(new_cmd, shell=True, stdout=PIPE)
async def test(cmd):
m = main()
await m.run(cmd)
while True:
proc = m.get_proc()
line = await proc.stdout.readline()
if not line:
break
print(line.decode().strip())
asyncio.run(test("ping 127.0.0.1"))