简体   繁体   English

为什么Java Processbuilder不能在其自己的目录中运行PMCMD(informatica命令),但可以在命令提示符下正常运行

[英]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();" 我是Java Process Builder的新手,正在尝试运行Informatica的命令(PMCMD命令),但是在“ 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. 我认为当您仅用pmcmd替换在构造函数中传递的cmd时。 Try doing this: 尝试这样做:

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

You can remove the argument passed in the ProcessBuilder constructor. 您可以删除在ProcessBuilder构造函数中传递的参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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