Sketch for solution:
Create an HTML file that contains the layout for your web page, with a dedicated DIV for the output of the script:
<html> <body> <div id="scriptoutput"></div> <script type="text/javascript" src="localhost:8000/runscript"/> </body> </html>
This HTML file can be used from any server you want.
Now write a simple http server that runs the script and converts each line into a javascript command (example in python):
import os f = os.popen('ping 127.0.0.1') for i in range(30): ln = f.readline() print "document.getElementById('scriptoutput').innerHTML += '<pre>%s</pre><br/>';" % ln
You can use any CGI / WSGI server for the task, or if performance is not critical, even use Python's own BaseHTTPServer class.
This can do the trick, as most browsers analyze and execute Javascript scripts as they are received (and not only after the request is completed) - note that polling or server memory is not required!
adamk
source share