import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;

public class ProcessLogger extends Thread {
    private InputStream is;

    private OutputStream os;

    public ProcessLogger(InputStream is, OutputStream redirect,
            String threadName) {
        super(threadName);
        this.is = is;
        this.os = redirect;
    }

    public void run() {
        PrintWriter pw = null;
        try {
            pw = new PrintWriter(this.os, true);
            InputStreamReader isr = new InputStreamReader(this.is);
            BufferedReader br = new BufferedReader(isr);
            String line = null;
            while ((line = br.readLine()) != null) {
                pw.println(line);
            }
            pw.flush();
        catch (IOException ioe) {
            ioe.printStackTrace();
        finally {
            if (pw != null)
                pw.close();
        }
    }
}