简体   繁体   English

尝试从另一个Java程序调用时出现目录错误

[英]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.

相关问题 尝试从Perl脚本执行Java程序时出错 - Error when trying to execute a java program from a perl script 尝试从命令行调用Java程序时出现“无法识别为命令”消息 - “Unrecognized as command” message when trying to call Java program from command line 从另一个 java 程序编译 java 项目时 Java 类路径错误 - Java Classpath Error When compiling a java project from another java program 尝试从另一个 class Java Selenium Z0F10ECB77876532AE8AZAE1B48 调用方法后出现 NullPointerException 错误 - NullPointerException error after trying to call a method from another class Java Selenium TestNG 尝试从VCS导入项目时出现“原因:错误= 2,没有这样的文件或目录”-Linux上的Java Home问题 - “Cause: error=2, No such file or directory” when trying to import project from VCS - Java Home issue on Linux 当程序从另一个目录运行时,DriverManager.getConnection不起作用 - DriverManager.getConnection not working when program runs from another directory 尝试使用ObjectDraw运行Java程序时线程“ main”错误 - Exception in thread “main” error when trying to run a java program with objectdraw 尝试使用javac编译.java helloworld程序时出错 - Error when trying to compile .java helloworld program using javac 尝试运行Java代码时程序顶部出现错误 - Error at top of program when trying to run java code java.lang.NumberFormatException尝试运行程序时显示错误 - java.lang.NumberFormatException Error shows when trying to run program
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM