使用带多个参数的 Runtime.getRuntime().exec

Using Runtime.getRuntime().exec with multiple parameters

所以我尝试使用 Runtime.getRuntime().exec 从 Java 代码执行 openview 命令。这个确切的命令在服务器上的命令提示符下运行良好,执行必要的更新,但在通过 Java 代码执行时无法执行。问题是它 returns 退出成功状态代码,即通过 Java 调用时为“0”,但不执行它应该执行的更新(看起来好像没有执行) .

命令如下:

opcmsg application='Tester Down 11' object='My Support' severity=minor msg_grp='MyGroup' msg_text='DEV: -m=New Details:Request Detail description'

这是代码:

String[] command = { 
    "opcmsg", 
    "application=\'Tester Down 11\'", 
    "object=\'My Support\'", 
    "severity=minor", 
    "msg_grp=\'MyGroup\'", 
    "msg_text=\'DEV: -m=New Details:Request Detail description\'" 
}
p = Runtime.getRuntime().exec(command);

InputStream stderr = p.getErrorStream();
InputStreamReader isr = new InputStreamReader(stderr);
BufferedReader br = new BufferedReader(isr);
String errorDescription = null;

while ( (errorDescription = br.readLine()) != null)
    LOGGER.info(errorDescription);

    exitStatus = p.waitFor();
    LOGGER.info("exitStatus : " + exitStatus);

这有效:

String[] command = { "/bin/sh",
     "-c",
     "opcmsg application=\'Tester Down 11\' object=\'My Support\' severity=minor msg_grp=\'MyGroup\' msg_text=\'DEV: -m=New Details:Request Detail description\' "  }