[英]Directory error when trying to call from another java program
I'm trying to call a java program from another java program in a different directory. 我试图从另一个目录中的另一个Java程序调用Java程序。 I get a "no such file or directory" error but I can copy and paste the directory I'm trying to reach from the error and it works fine. 我收到“没有这样的文件或目录”错误,但是我可以复制并粘贴从错误中尝试访问的目录,它可以正常工作。
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]$
Try giving the command a full path 尝试为命令提供完整路径
So instead of 所以代替
java --classpath ...
do 做
C:\Program Files\Java\jdk1.7\bin\java --classpath ...
Also, you might need to quote the arguments if they have spaces 另外,如果参数中有空格,则可能需要用引号引起来
Figured it out 弄清楚了
Needed to be: 需要为:
Process x = Runtime.getRuntime().exec(new String[]{"java","-classpath",postProcPath,"PostProcAuto",outFile.split("\\."), "2"});
Rather than: 而不是:
Process x = Runtime.getRuntime().exec(new String[]{"java -classpath " + postProcPath +" PostProcAuto", outFile.split("\\."), "2"});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.