1

Hey all not sure if there is a solution to my situation but here goes.

I am sending some 9 cmd.exe commands:

static String startDaemon_2             = "scm daemon start"; //Start Daemon
static String isRQRunning_3             = "RQAdapter.bat status"; //Check if RQ is running
static String startRQ_4                 = "RQAdapter.bat start"; //Start RQ
...etc etc....

And this is my main code to fire off the commands:

static ProcessBuilder processBuilder    = new ProcessBuilder();
static Process process                  = null;
static BufferedReader reader            = null;

public static Object steps(String cmds, String dir_) {
    processBuilder.command("cmd.exe", "/c", cmds);
    processBuilder.directory(new File(dir_));

    try {
        process     = processBuilder.start();
        reader      = new BufferedReader(new InputStreamReader(process.getInputStream()));
        String line = "";

        while ((line = reader.readLine()) != null) {
            System.out.println(line);

            if (line.contains("Key:")) {
                return true;
            } else if (line.contains("successfully")) {
                return true;                                
            } else if (line.contains("background")) {
                return true;
            } else if (line.contains("not")) {
                //Load the adapter then
                return "startRQM_4"; 
            } else if (line.contains("sandbox")) {
                return true;
            } else if (line.contains("Misfit")) {
                return true;
            // repair goes here
            } else if (line.contains("Unresolved")) {
                //at this point theres no need to carry on. theres a conflick
                return "fix";
            } 
        }

        int exitCode = process.waitFor();
        System.out.println(line);

        if (exitCode == 0) {
            return true;
        } else {
            return false;
        }
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    } catch (InterruptedException e) {
        e.printStackTrace();
        return false;
    }        
}

And I call that function this way:

result = steps(startDaemon_2, scmDir);
if (result == "false") { System.out.println("not true"); }

result = steps(isRQMRunning_3, scmDir);
etc..... etc......

When I fire these same commands off in an actual cmd window it works just fine. Does what it should do. However, when the java program does the exact same thing it seems not to work even though there are no error.

Then I started thinking that maybe I need to define ProcessBuilder, process, reader

But it seems to still not work and without errors.

Is there some other type of way to do a few cmd.exe in the same setting? Seems it's just doing new stuff for each command.

What I mean by the last sentence is that I log in using the first command and then it goes to the other one which is start daemon, etc. But it seems to act like its brand new for each call (a.k.a. Isn't not logged in when firing the 2nd command, etc...)

StealthRT
  • 10,108
  • 40
  • 183
  • 342

0 Answers0