Running pmcmd from java

2019-08-17 08:57发布

I am trying to run pmcmd and pass arguments from java. This is my code :

String cmd="C:\\Informatica\\9.6.1\\clients\\PowerCenterClient\\CommandLineUtilities\\PC\\server\\bin\\pmcmd.exe";
    final Process cmdProcess;

    cmdProcess = Runtime.getRuntime().exec(new String[]{cmd,"connect -sv IS_NAME -d DOMAIN_NAME -u USER -p PWD"});
    cmdProcess.getOutputStream().close();

The problem is I am not able to get the desired output. I get the following error:

ERROR: Unknown command [connect]

When I try the same command on the command line, it works.

pmcmd>connect -sv IS_NAME -d DOMAIN_NAME -u USER -p PWD

The output:

Connected to Integration Service:[IS_NAME].

Can anyone tell what mistake I am doing?

3条回答
迷人小祖宗
2楼-- · 2019-08-17 09:24

(adding my comment as an answer, after it worked according to the OP)

Your command line example suggests that the connect -sv ... is issued within the pmcmd process, and not provided as an argument.

So you should probably send that to the process' STDIN (accessed by cmdProcess.getOutputStream()) instead of passing as argument to the call.

查看更多
爷、活的狠高调
3楼-- · 2019-08-17 09:31

I had to issue a command within the pmcmd process. So I modified my code and it works :

                String cmd="C:\\Informatica\\9.6.1\\clients\\PowerCenterClient\\CommandLineUtilities\\PC\\server\\bin\\pmcmd.exe";
                final Process cmdProcess;

                cmdProcess = Runtime.getRuntime().exec(new String[]{cmd,""});
                OutputStream out = cmdProcess.getOutputStream();
                out.write("connect  -sv IS_NAME -d DOMAIN_NAME -u USER -p PWD".getBytes());
                out.close;
查看更多
forever°为你锁心
4楼-- · 2019-08-17 09:33

pmcmd works in two modes, command line and interactive. connect command works in interactive mode only.

When invoking from java, you are using command line mode, and do not need to connect first. You can directly invoke the command you intend to run (ex. startWorkflow) and provide the connection parameters with that command like below:

pmcmd startworkflow -sv MyIntService -d MyDomain -u seller3 -p jackson ‑f SalesEast wf_SalesAvg

More details here.

查看更多
登录 后发表回答