I have this code which is working fine. How to send my input to the Java Process Builder?
Here is the code:
PrintStream out = System.out;
Runtime rt = Runtime.getRuntime();
try {
out.println("Executing a command in a separate process...");
Scanner input = new Scanner(System.in);
String str = input.nextLine();
Process proc = rt.exec(str);
/*OutputStream procIn = proc.getOutputStream();
procIn.write("My Code".getBytes());
procIn.close();*/
InputStream procOut = proc.getInputStream();
byte[] msgOut = new byte[64];
int len = procOut.read(msgOut);
procOut.close();
out.println("Output from the command: "
+new String(msgOut,0,len));
out.println("Waiting for the process to finish...");
int rc = proc.waitFor();
out.println("Status code returned by the process "+rc);
} catch (Exception e) {
e.printStackTrace();
}
I need to know how to use this section:
/*OutputStream procIn = proc.getOutputStream();
procIn.write("My Code".getBytes());
procIn.close();*/
Thanks in advance for any help.