vendredi 18 septembre 2015

How to know whether command executed using Runtime.exec() is giving some output or is only waiting and not giving any output?

I am trying to run an accurev command using Java Runtime exec (as described in code below). Since I have a network problem so when the login command is executed the command keeps on waiting for the response and doesn't time out. So how should I be able handle this error.

private static void accurevLogin() throws IOException {
    Runtime runTime = Runtime.getRuntime();
    String userName = prop.getProperty("UserName");
    String password = prop.getProperty("Password");
    String command = (new StringBuilder("accurev login ")).append(userName).append(" ").append(password).toString();
    Process ps = null;
    try {
        ps = runTime.exec(command);
    } catch (IOException e) {
        System.out.println("Command Execution Error!");
    }
    /* Error handling Code */
    System.out.println("ACCUREV LOGGED IN");
}

When I use

BufferedReader input = new BufferedReader(new InputStreamReader(ps.getInputStream()));

input.readline in the loop will keep on running and I am not able to check the output.



from Newest questions tagged java - Stack Overflow http://ift.tt/1P6S2No
via IFTTT

Aucun commentaire:

Enregistrer un commentaire