我有一个 IRB,我想将它发送到后台并使用 Java 评估 IRB 的命令。我尝试了类似 [1] 的方法,但它无法识别任何命令。
[1]
String response = "";
ProcessBuilder pb = new ProcessBuilder(myIrb); //myIrb is a unix script which starts the IRB
try {
pb.command(myCommand);
Process proc = pb.start();
InputStream input = proc.getInputStream();
int i;
while((i = input.read()) != -1) {
char c = (char)i;
response += c;
} catch (IOException e) {
response = e.toString();
}
System.out.println(response);