try {
String comd ="E:/ior1.txt";
Runtime rt = Runtime.getRuntime();
rt.exec("C:/tes1.bat"+comd+"");
System.out.println("Process exitValue: ");
}
catch (Exception e)
{
System.out.println("Unexpected exception Trying to Execute Job: " +e);
}
Run Code Online (Sandbox Code Playgroud)
但是当我跑步时,我得到了这样的例外
Unexpected exception Trying to Execute Job: java.io.IOException: CreateProcess:
C:/tes1.batE:/ior1.txt error=2
Press any key to continue . . .
Run Code Online (Sandbox Code Playgroud)
这是批处理文件的内容
echo "testing"
echo %1
Run Code Online (Sandbox Code Playgroud)
.bat之后缺少空白(在rt.exec行中)
你也可以尝试执行:
rt.exec("cmd /c c:/tes1.bat "+comd);
Run Code Online (Sandbox Code Playgroud)