为什么PMCMD(informatica命令)不是由Java Processbuilder从其自己的目录运行,而它在命令提示符下工作正常

问题描述 投票:0回答:1

我是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)
java informatica-powercenter
1个回答
0
投票

我想当你用pmcmd替换构造函数中传递的cmd时。试着这样做:

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

您可以删除ProcessBuilder构造函数中传递的参数。

© www.soinside.com 2019 - 2024. All rights reserved.