我有这个工作正常的代码。如何将我的输入发送到 Java Process Builder?
这是代码:
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();
}
我需要知道如何使用这个部分:
/*OutputStream procIn = proc.getOutputStream();
procIn.write("My Code".getBytes());
procIn.close();*/
提前感谢您的帮助。