I have an Apache web server and I made a python script to run a command. Command that I'm running is launching a ROS launch file, that is working indefinitely. I would like to read output from the subprocess live and display it in the page. With my code so far I could only manage to make output to be printed after I terminate the process. I've tried all kinds of solutions from the web but none of them seem to work
command = "roslaunch package test.launch" proc = subprocess.Popen( command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env, shell=True, bufsize=1, ) print "Content-type:text/html\r\n\r\n" for line in iter(proc.stdout.readline, ''): strLine = str(line).rstrip() print(">>> " + strLine) print("<br/>")
sys.stdout.flush()?subprocessand just print with a pause:print "Content-type:text/html\r\n\r\n" for i in range(100): print ("%02d" % i) * 10000; time.sleep(1)(perhaps you should useTransfer-Encoding: chunk)subprocess. See how to create a minimal complete code example