Hi all,

I have two external applications. I'm trying to redirect stdin one of them to stdout another. And vice versa. stderr both of them I am trying redirect to System.out

I wrote the code, but it does not work.

Java Code:
package pipes;

import java.io.IOException;

public class Main
{

  public static void main(String[] args) throws IOException
  {
    Process rz = Runtime.getRuntime().exec("rz");
    Process sz = Runtime.getRuntime().exec("sz -b /home/alexanis/minicom.log");

    Thread sz2rz = new Thread(new PipeThread("sz2rz", sz.getInputStream(), rz.getOutputStream()));
    Thread rz2sz = new Thread(new PipeThread("rz2sz", rz.getInputStream(), sz.getOutputStream()));
    Thread sz2err = new Thread(new PipeThread("sz2err", sz.getErrorStream(), System.out));
    Thread rz2err = new Thread(new PipeThread("rz2err", rz.getErrorStream(), System.out));

    sz2rz.start();
    rz2sz.start();
    sz2err.start();
    rz2err.start();
  }
}
Java Code:
package pipes;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class PipeThread implements Runnable
{

  InputStream in = null;
  OutputStream out = null;
  String name;

  PipeThread(String name, InputStream in, OutputStream out)
  {
    this.in = in;
    this.out = out;
    this.name = name;
  }

  public void run()
  {
    int c;
    try
    {
      while ((c = in.read()) > 0)
      {
        out.write(c);
        out.flush();
      }
      out.close();
    } catch (IOException ex)
    {
      ex.printStackTrace();
    }
  }
}
Does anyone know how to do this?