Question

Recently I am trying to write an java application to call SCM.exe to execute the code loading job. However, after I successfully execute the SCM load command via java, I found that I actually cannot really download the code (as using the command line, the password need to be entered after execute the SCM load command). May I know how can I enter this password just after I use the process to run the SCM in java? How can I get the output of the command line and enter something into the command line?

Thanks a million, Eric

Was it helpful?

Solution

Since I don't know what exactly SCM.exe in your case is, I'm answering only what deals with the input/output redirection requirements in an abstract sense. I assume further that you are calling SCM.exe with whatever parameters it needs through System("...") and this is where you are unable pass any further input (stdin of the called process).

You need, instead, to be able to, upon receiving the request for password, pass it to the stdin of the other process, which is solved by using pipes in the classical sense (since you are presumably on Windows, YMMV). More generally, you are dealing with a very simple case of IPC.

In Java you may find an adequate solution by using ProcessBuilder [1] (never did myself, though -- i'd use things a lot simpler than java for this purpose, but I digress...).

An outline of a solution would be:

  1. call the process, having its input and output being handled as output/input streams from your caller java process.
  2. read the output of your process until you are queried the password
  3. write the password
  4. carry on as needed.

If you need further clarification you may need to give more details about your scenario.

[1] http://docs.oracle.com/javase/7/docs/api/java/lang/ProcessBuilder.html

OTHER TIPS

public class test { public static void main(String[] args){

    try {
        System.out.println("");
        String commands = "C:/swdtools/IBM/RAD8/scmtools/eclipse/scm.exe load -d C:/users/43793207/test -i test -r eric-repo";  
        // load -d C:/users/43793207/test -i test -r eric-repo 

        test test=new test();
        test.execCommand(commands);

    } catch (Exception e) {
        e.printStackTrace();
    }
}

public void execCommand(String commands){
    //ProcessBuilder pb = new ProcessBuilder(Command);
    //pb.start();
     String line;

    try {
        //Process pp = Runtime.getRuntime().exec(commands);
        System.out.println(commands);
        Process process = new ProcessBuilder(commands).start();
        InputStream is = process.getInputStream();
        InputStreamReader isr = new InputStreamReader(is);
        BufferedReader br = new BufferedReader(isr);


        while ((line = br.readLine()) != null) {
            System.out.println(line);
                }
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top