tail -f in a webbrowser

后端 未结 3 1366
梦如初夏
梦如初夏 2020-12-10 15:44

I\'ve created a Python script that monitors a logfile for changes (like tail -f) and displays it on a console. I would like to access the output of the Python script in a we

3条回答
  •  死守一世寂寞
    2020-12-10 16:01

    I don't have any Python or Django experience but I'd assume you can make a system call like tail in Python and relay the details.

    From there, I'd use a jQuery .ajax() call with a javascript setInterval() loop to your Python script and output the results to a div on the web page. Overall a pretty simple solution.

    In this instance, you really wouldn't need to use an open tail -f system call because the nature of the JS setInterval() method, the Python script will be called over and over again until the JS clearInterval() method is called. You'll aggregate your script details in either Python or JS depending where you want to do the work. I'd suggestion Python since you'd have more robust features at your fingertips and you would send less data via the AJAX call. Theoretically, there probably shouldn't be too much logic needed in the jQuery code on the front end. Just display the data.

    • http://api.jquery.com/jQuery.ajax/
    • http://www.w3schools.com/jsref/met_win_setinterval.asp

提交回复
热议问题