J2EE: Directing process output to the client

T

Tim Slattery

I'm writing a servlet that runs an external program, captures the HTML
that it writes out, and sends that to the client. So I'm doing this:

Runtime rt = Runtime.getRuntime();
Process pr = rt.exec(cmdline, env, new File(cgiDir));

I can send data to the process's STDIN, and retrieve its STDERR and
write it to a file, so I know it's running, and I KNOW that it's
written something to STDOUT. Here's how I'm trying to process that:


ServletOutputStream os = response.getOutputStream();
new OutputPollster(pr.getInputStream(), os).start();



Where OutputPollster is:

class OutputPollster extends java.lang.Thread
{
private java.io.InputStream m_is;
private ServletOutputStream sosOut;

OutputPollster(java.io.InputStream is, ServletOutputStream
sosOut)
{
m_is = is;
this.sosOut = sosOut;
}

public void run()
{
int len;
byte buf[] = new byte[128];
try
{
while (-1 != (len = m_is.read(buf)))
{
String chunk = new String(buf, 0, len);
sosOut.print(chunk);
}

sosOut.flush();
}
catch (java.io.IOException ex)
{
//deal with the exception
System.out.println("Error: " + ex.getMessage());
}
}

But absolutely NOTHING gets sent to the client browser! What's wrong
with this?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top