It's delicate in terms of security, but it's troublesome to SSH just to type one command, so I often put it in the server secretly. The sample is ls, but even make works.
When \ x0a
appears in the middle, the point is to replace it with<BR>
to make the output easier to see.
#!/usr/bin/env python
import sys
from subprocess import Popen, PIPE
print "Content-Type: text/html\n\n"
p = Popen(["ls","-al"], stdout=PIPE)
while 1:
c = p.stdout.read(1)
if not c:
break
if c == bytes("\x0a"):
print "<br>"
sys.stdout.write(c)