I want to write a program which executes JARs and gets their output. When the JAR program has only a print statement it works fine, but when it asks for input during execution, the program freezes.
Code of the JAR file program:
import java.util.*;
public class demo {
    public static void main(String r[]) {
        Scanner sc = new Scanner(System.in);
        System.out.println("Hello ...");
        System.out.println("please enter the number :");
        int i = sc.nextInt();
        System.out.println(" number : " + i);
    }
}
Code of the original program which runs the JAR files:
public class jartorun {
    public static void main(String arg[]) throws IOException {
        String t = "javaw -jar D:\\jarcheck\\temp.jar";
        Process p = Runtime.getRuntime().exec(t);
        BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
        String line = "";
        while ((line = input.readLine()) != null) {
            System.out.print(line + "\n");
        }
        input.close();
    }
}
I can give input to the JAR  using process.getOutputStream(), but how would I use it so I can create a program which can give input to a JAR  and read its output simultaneously?
 
     
     
    