简体   繁体   中英

Why PMCMD (informatica command) is not run by Java Processbuilder from its own directory while it works fine with command prompt

I'm new to Java Process Builder and trying to run the Informatica's commands (PMCMD commands) but I am getting the following error at line "Process process = builder.command(commandLine).start();" of my below code snippet.

**"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)

I think when you are replacing the cmd passed in the constructor with only pmcmd. Try doing this:

commandLine.add("cmd");
commandLine.add("/C");
commandLine.add("pmcmd");

You can remove the argument passed in the ProcessBuilder constructor.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM