Home » Python » javascript – Display live stream logs in browser like Jenkins console log-Exceptionshub

javascript – Display live stream logs in browser like Jenkins console log-Exceptionshub

Posted by: admin February 24, 2020 Leave a comment

Questions:

views.py

def runcommand(command, directory):
    os.chdir(directory)
    p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    output, errors = p.communicate()
    os.chdir('/Users/pr20121476/NAA/Django_Proj/')
    return output, errors


def stream(request):
    output, errors = runcommand("/Users/pr20121476/NAA/Django_Proj/app/dashboard/test.sh", "/Users/pr20121476/NAA/Django_Proj/")
    template = loader.get_template('dashboard/run.html')
    context = {
        'output': output,
        'errors': errors
    }
    return HttpResponse(template.render(context, request))

run.html

{% extends 'dashboard/base.html' %}
{% block extrahead %}
<script type="text/javascript">
        $(function(){
            $('a.extendable').click(function(){
                $(this).after($('<div class="external-content"></div>').load($(this).attr('href') + ' #content'));
                return false;
            });
        });
    </script>
{% endblock extrahead %}

{% block content %}

        <br>
    <div id="output">{{ output }}</div>
        <br>
    <div id="error">{{  errors }}</div>

 {%  endblock %}

url.py

path('roadrunner/', TemplateView.as_view(template_name='dashboard/roadrunner.html'), name='roadrunner'),
path('roadrunner/run', views.stream, name="roadrunner/run"),

My requirement is to display output of script in a HTML page as the output log process.
In other ways live stream logs like Jenkins console log.

Kindly provide some hint or any piece of solution .

How to&Answers: