0

我正在尝试从另一个目录中的另一个 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]$
4

2 回答 2

0

尝试为命令提供完整路径

所以而不是

java --classpath ...

C:\Program Files\Java\jdk1.7\bin\java --classpath ...

此外,如果参数有空格,您可能需要引用它们

于 2012-12-06T21:53:55.943 回答
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"});
于 2012-12-07T21:22:12.617 回答