我面臨以下錯誤:爪哇 - > CreateProcess的錯誤= 2,系統找不到指定的文件
java.io.IOException: Cannot run program "C:\abc\man\b\manu.bat C:\Users\12x\test\testFiles\abc.properties" (in directory "C:\Users\12x\test\testFiles\abc.properties"): CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048).
請找我使用的代碼:
public class TestProcess {
public TestProcess(Path workPath, Path exe, Path logbackConfig,
Path propertyfile) throws IOException {
String exeSuffix = "";
if (OS.indexOf("win") >= 0) {
exeSuffix = ".bat";
}
builder = new ProcessBuilder()
.directory(workPath.toFile())
.command(workPath.resolve(exe).toAbsolutePath().toString() + exeSuffix+ " " + propertyfile)
.redirectOutput(Redirect.INHERIT)
.redirectError(Redirect.INHERIT);
我的目標是運行bat文件(該文件存在於C:\ abc \ man \ b文件夾中),然後運行abc.properties(位於另一個文件夾C:\ Users \ 12x \ test \ testFiles中)。
在上面的代碼中,workPath有
C:\abc\man\b
和propertyfile具有
C:\Users\12x\test\testFiles
我想這一點,但得到了以下錯誤: –
的方法指令(名單) ProcessBuilder類型不適用於參數 \t(字符串,路徑) –
@sandeepgoyal所以使用'propertyfile.toString()'。 – EJP