例外
/usr/sbin/asterisk -rx "dongle sms dongle0 km FROM> some address TO> some address 20 kms. Please respond in 2 minutes, ok, yes, 1 or book. Else ignore"
java.io.IOException: Cannot run program "/usr/sbin/asterisk -rx "dongle sms dongle0 " (in directory "."): java.io.IOException: error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:488)
at java.lang.Runtime.exec(Runtime.java:610)
at org.apache.commons.exec.launcher.Java13CommandLauncher.exec(Java13CommandLauncher.java:58)
at org.apache.commons.exec.DefaultExecutor.launch(DefaultExecutor.java:254)
at org.apache.commons.exec.DefaultExecutor.executeInternal(DefaultExecutor.java:319)
at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:160)
at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:147)
at Test.main(Test.java:33)
Caused by: java.io.IOException: java.io.IOException: error=2, No such file or directory
at java.lang.UNIXProcess.<init>(UNIXProcess.java:164)
at java.lang.ProcessImpl.start(ProcessImpl.java:81)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:470)
... 7 more
代码
public static void main(String[] args) {
CommandLine commandLine = new CommandLine("/usr/sbin/asterisk -rx \"dongle sms dongle0 ");
DefaultExecutor executor = new DefaultExecutor();
String cmd[] = new String[8] ;
cmd[0] = "" ; // phonenumber
cmd[1] = "" ; // distancefrom customer
cmd[2] = "km FROM>" ;
cmd[3] = " some address " ;
cmd[4] = " TO>" ;
cmd[5] = " some address ";
cmd[6] = "20" ;
cmd[7] = "kms. Please respond in 2 minutes, ok, yes, 1 or book. Else ignore\"";
try {
for (int i = 0 ; i < cmd.length ; i++)
commandLine.addArgument(cmd[i], false) ;
System.out.println(commandLine.toString());
executor.execute(commandLine);
} catch (IOException e) {
e.printStackTrace();
}
}
我试过了
CommandLine commandLine = new CommandLine("/bin/sh -c echo | sudo /usr/sbin/asterisk -rx \"dongle sms dongle0 "); 我得到了 /bin/sh 完全相同的异常
CommandLine commandLine = new CommandLine("/bin/dash -c echo | sudo /usr/sbin/asterisk -rx \"dongle sms dongle0 "); 我得到了 /bin/dash 完全相同的异常