using process builder to get the stream of this process

30 Views Asked by At

I'm using a common solution which is using the BufferedReader class in order to get the the input stream but it seems that if I can see the command console opening with the application running, I cannot get what's in there, there is no data in the variables and it's stuck at the readline() step, surely because the data is not flushed as the app is constantly running

public static void executeCommandOnLocalMachine(ProcessBuilder builder) throws Exception {
    builder.redirectErrorStream(true);
    Process process = builder.start();
    BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
    String line = reader.readLine();
    while (line != null) {
        Log.info(line);
        if(line.toLowerCase().contains("started"))
            break;
        line = reader.readLine();

    }
}

called by

public static String START_APPLICATION_MANAGER_COMMAND ="cd /D %VARENV%/../Application && start java -jar application.jar";


public static void startApplicationManager() throws Exception {
            ProcessBuilder builder = new ProcessBuilder("cmd.exe", "/C", GeneralConstants.START_APPLICATION_COMMAND);

    ProcessManager.executeCommandOnLocalMachine(builder);
}
1

There are 1 best solutions below

3
criztovyl On

if you use cmd start, cmd starts the process in a completely new window, so to access process output, simply leave off start.