I'm trying to write a java program that runs a system command (shell) and
send/receives data to/from that process. Here is an example:

BufferedReader data = new BufferedReader(new FileReader(DATAFILE));
Process p = Runtime.getRuntime().exec(COMMAND);

PrintWriter pOut = new PrintWriter(
new OutputStreamWriter(p.getOutputStream())
);
BufferedReader pIn = new BufferedReader(
new InputStreamReader(p.getInputStream())
);

String buf;

// send data to sub-process
while ((buf = data.readLine()) != null) { pOut.println(buf); }

// read data from sub-process and display on screen
while ((buf = pIn.readLine()) != null) { System.out.println(buf); }

This is working fine for up to some unknown amount of data being SENT to to
sub-process (I'm not having problems reading the data coming back from the
sub-process). But when I try to send a large amount of data to the
sub-process I get problems; like locking up, a portion of the data repeating
continuously, or the sub-process doesn't actually receive all of the data.

Your first thought might be to just open a socket to the sub-process, but it
doesn't have socket capabilities.

Any help would be appreciated.
Thanks in advance.