Java Runtime.exec pode outro programa java que usa stdi

Ocorreu um problema em que, ao usar o Java Runtime para executar outro programa java, o programa congela porque o outro programa requer stdin. Há um problema ao lidar com o stdin após executar outro programa java com o Runtime exec ().

Aqui está um código de exemplo que não consigo trabalhar. Isso é possível?

import java.util.*;
import java.io.*;

public class ExecNoGobble
{
    public static void main(String args[])
    {
        if (args.length < 1)
        {
            System.out.println("USAGE: java ExecNoGobble <cmd>");
            System.exit(1);
        }

        try
        {            
            String[] cmd = new String[3];
                cmd[0] = "cmd.exe" ;
                cmd[1] = "/C" ;
                cmd[2] = args[0];
            Runtime rt = Runtime.getRuntime();
            System.out.println("Execing " + cmd[0] + " " + cmd[1] + " " + cmd[2]);
            Process proc = rt.exec(cmd);
            int exitVal = proc.waitFor();
            System.out.println("ExitValue: " + exitVal);        
        } catch (Throwable t)
          {
            t.printStackTrace();
          }
    }
}

E o arquivo ReadInput.java:

import java.io.*;

public class ReadInput {

   public static void main (String[] args) {

      //  prompt the user to enter their name
      System.out.print("Enter your name: ");

      //  open up standard input
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

      String userName = null;

      //  read the username from the command-line; need to use try/catch with the
      //  readLine() method
      try {
         userName = br.readLine();
      } catch (IOException ioe) {
         System.out.println("IO error trying to read your name!");
         System.exit(1);
      }

      System.out.println("Thanks for the name, " + userName);

   }

}  // end of ReadInput class

E, finalmente, o arquivo em lotes que o inicia:

@echo off

echo.
echo Try to run a program  (click a key to continue)
echo.
pause>nul
java ExecNoGobble "java -cp . ReadInput"
echo.
echo (click a key to end)
pause>nul

Eu também postei a pergunta aqui:http: //forums.oracle.com/forums/message.jspa? messageID = 9747449

questionAnswers(1)

yourAnswerToTheQuestion