This Java tip illustrates a method of reading an output from a command execution. Developer after executing the command from the code may use this tip to read the output. This output may then be further used in the code for various purposes.

   try {
        // Execute a command
        String command = "ls";
        Process child = Runtime.getRuntime().exec(command);
        // Read from an input stream
        InputStream in = child.getInputStream();
        int c;
        while ((c = != -1) {
    } catch (IOException e) {