Отображение журналов и хода выполнения команды cmd в реальном времени на веб-странице python

Когда пользователь нажимает на кнопку на веб-странице django, она должна запускать команду cmd. с которой она должна также показывать прогресс и логи команды в прямом эфире на странице.

Я могу выполнить команду cmd через функцию python по нажатию кнопки, но не могу одновременно отобразить логи и прогресс на странице.

Помогите, пожалуйста. Заранее спасибо.

def exect(request):

cmnd = 'netstat'
try:
    
    checkReturncode = subprocess.Popen(cmnd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False)
    print(checkReturncode)
    while True:
        output = checkReturncode.stdout.readline()
        #print(type(output))
       
        if checkReturncode.poll() is not None:
            break
        if output:
            otpt=output.strip()
            print(otpt) #This prints the output line by line, but I need to print this on the web page live
            
    rc = checkReturncode.poll()

    if checkReturncode.returncode == 0:
        print(f"command executed successfully! returncode is {checkReturncode}")
    else:
        print("something went wrong..", checkReturncode)
        print(checkReturncode)

except FileNotFoundError as e:
    print(e)

print("executed Successfully")
return HttpResponse('')
Вернуться на верх