我是Java Process Builder的新手,正在尝试运行Informatica的命令(PMCMD命令),但是在行“ Process process = builder.command(commandLine).start();”处出现以下错误。 下面的代码段。
**"java.io.IOException: Cannot run program "pmcmd" (in directory "C:\data\Informatica\10.1.1\clients\PowerCenterClient\CommandLineUtilities\PC\server\bin"): CreateProcess error=2, The system cannot find the file specified[0;39m"**
**PMCMD exact path on my PC**
C:\data\Informatica\10.1.1\clients\PowerCenterClient\CommandLineUtilities\PC\server\bin
**My code:**
ProcessBuilder builder = new ProcessBuilder("cmd.exe");
builder.redirectInput(ProcessBuilder.Redirect.INHERIT);
builder.redirectOutput(ProcessBuilder.Redirect.INHERIT);
builder.redirectErrorStream(true);
builder.directory(new File("C:\\data\\Informatica\\10.1.1\\clients\\PowerCenterClient\\CommandLineUtilities\\PC\\server\\bin\\"));
List<String> commandLine = new ArrayList<String>();
commandLine.add("pmcmd");
Process process = builder.command(commandLine).start();
int status = process.waitFor();
System.out.println("Status: " + status);
BufferedReader r = new BufferedReader(new InputStreamReader(process.getInputStream()));
//BufferedReader r = new BufferedReader(new //OuputStream(process.getOutputStream()));
//OutputStream os = process.getOutputStream();
//System.out.println(os.flush());
//BufferedReader r = new BufferedReader(new InputStreamReader(process.getOutputStream()) );
String line;
while (true) {
line = r.readLine();
if (line == null) { break; }
System.out.println(line);
}
**Stack Tarce:**
java.io.IOException: Cannot run program "pmcmd"
(in directory "C:\data\Informatica\10.1.1\clients\PowerCenterClient\CommandLineUtilities\PC\server\bin"): CreateProcess error=2, The system cannot find the file specified[0;39m
[31m at java_lang_ProcessBuilder$start$5.call(Unknown Source)[0;39m
[31m at TC3_ETL workflow via JSch.run(TC3_ETL workflow via JSch:52)[0;39m
[31m at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)[0;39m
[31m at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)[0;39m
[31m at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:328)[0;39m
[31m at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:319)[0;39m
[31m at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:298)[0;39m
[31m at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:290)[0;39m
[31m at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:224)[0;39m
[31m at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:106)[0;39m
[31m at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:97)[0;39m
[31m at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)[0;39m
[31m at TempTestCase1551005932981.run(TempTestCase1551005932981.groovy:22)[0;39m
[31mCaused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified[0;39m
[31m at java_lang_ProcessBuilder$start$5.call(Unknown Source)[0;39m
[31m at Script1550833086592.run(Script1550833086592.groovy:52)
答案 0 :(得分:0)
我认为当您仅用pmcmd替换在构造函数中传递的cmd时。尝试这样做:
commandLine.add("cmd");
commandLine.add("/C");
commandLine.add("pmcmd");
您可以删除在ProcessBuilder构造函数中传递的参数。