0

我有一个 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);
4

2 回答 2

0

If you want the thing to execute in the background, then you don't want to execute the Ruby script directly, you want to invoke a shell to execute the Ruby script.

For Windows, use "start". For Linux, use "&".

于 2012-07-31T16:45:06.953 回答
0

是否有任何特殊原因要在单独的 IRB 进程中评估 ruby​​ 而不是直接从 java 评估它?

http://kenai.com/projects/jruby/pages/RedBridge

这会简单得多。

于 2012-08-04T22:17:11.487 回答