I am running a .jar file which produces output in command prompt. I need the output from command prompt window to print it in a UI. I used the following code but it is not working in my case.
package ckmetrics;
import java.io.IOException;
public class CKMetrics {
    public static void main(String[] args) throws IOException {
        // TODO code application logic here
        String command ="java -jar CK-Metrics.jar Test.class";
        String ans = execCmd(command);
        System.out.println(ans);
    }
    public static String execCmd(String cmd) throws java.io.IOException {
        System.out.println(cmd);
        Process proc = Runtime.getRuntime().exec(cmd);
        java.io.InputStream is = proc.getInputStream();
        java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A");
        String val = "";
        if (s.hasNext()) {
            val = s.next();
            System.out.println("1");
        }
        else {
            val = "";
            System.out.println("2");
        }
        System.out.print(val);
        return val;
    }
}
Every time the the else condition is executed.
 
     
     
    