我正在尝试从另一个目录中的另一个java程序调用java程序。我得到一个“没有这样的文件或目录”错误,但我可以复制并粘贴我试图从错误中获得的目录,它工作正常。
Exception in thread "main" java.io.IOException: Cannot run program "java -classpath /home/paleus/directories/trunk/web/postProc PostProcAuto": java.io.IOException: error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:474)
at java.lang.Runtime.exec(Runtime.java:610)
at java.lang.Runtime.exec(Runtime.java:483)
at PreParseAuto.parseEmail(PreParseAuto.java:352)
at PreParseAuto.main(PreParseAuto.java:79)
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:467)
... 4 more
[paleus@vm20031 preParsing]$ java -classpath /home/paleus/directories/trunk/web/postProc PostProcAuto
Please run as: inFile outFile procType[Inferencing=0|Phone=1|Email=2|Addr=3]
[paleus@vm20031 preParsing]$
答案 0 :(得分:0)
尝试为命令提供完整路径
所以而不是
java --classpath ...
DO
C:\Program Files\Java\jdk1.7\bin\java --classpath ...
此外,如果参数有空格,您可能需要引用它们
答案 1 :(得分:0)
想出来
需要:
Process x = Runtime.getRuntime().exec(new String[]{"java","-classpath",postProcPath,"PostProcAuto",outFile.split("\\."), "2"});
而不是:
Process x = Runtime.getRuntime().exec(new String[]{"java -classpath " + postProcPath +" PostProcAuto", outFile.split("\\."), "2"});