Index: org/mortbay/servlet/CGI.java =================================================================== --- org/mortbay/servlet/CGI.java (revision 14165) +++ org/mortbay/servlet/CGI.java (working copy) @@ -64,6 +64,7 @@ private String _cmdPrefix; private EnvList _env; private boolean _ignoreExitState; + private boolean _autoFlushOutput; /* ------------------------------------------------------------ */ public void init() throws ServletException @@ -119,6 +120,7 @@ _env.set("PATH",_path); _ignoreExitState="true".equalsIgnoreCase(getInitParameter("ignoreExitState")); + _autoFlushOutput="true".equalsIgnoreCase(getInitParameter("autoFlushOutput")); Enumeration e=getInitParameterNames(); while (e.hasMoreElements()) { @@ -158,6 +160,7 @@ Log.debug("CGI: _docRoot : "+_docRoot); Log.debug("CGI: _path : "+_path); Log.debug("CGI: _ignoreExitState: "+_ignoreExitState); + Log.debug("CGI: _autoFlushOutput: "+_autoFlushOutput); } // pathInContext may actually comprises scriptName/pathInfo...We will @@ -332,7 +335,8 @@ } // copy cgi content to response stream... os = res.getOutputStream(); - IO.copy(inFromCgi, os); + IO.copy(inFromCgi, os, -1, _autoFlushOutput); + p.waitFor(); if (!_ignoreExitState) Index: org/mortbay/util/IO.java =================================================================== --- org/mortbay/util/IO.java (revision 14165) +++ org/mortbay/util/IO.java (working copy) @@ -175,6 +175,19 @@ OutputStream out, long byteCount) throws IOException + { + copy(in, out, byteCount, false); + } + + /* ------------------------------------------------------------------- */ + /** Copy Stream in to Stream for byteCount bytes or until EOF or exception. + * Optionally flush output after each write + */ + public static void copy(InputStream in, + OutputStream out, + long byteCount, + boolean autoFlushOutput) + throws IOException { byte buffer[] = new byte[bufferSize]; int len=bufferSize; @@ -193,6 +206,8 @@ byteCount -= len; out.write(buffer,0,len); + if (autoFlushOutput) + out.flush(); } } else @@ -203,6 +218,8 @@ if (len<0 ) break; out.write(buffer,0,len); + if (autoFlushOutput) + out.flush(); } } }