Q:

Println the return values of an executable

I have deploy an matlab .m file into an windows console application. The matlab file that I deploy is in fact a matlab function which have no arguments and return a list of integer. I am running that .exe from java code using process to run my executable file. I am tried to read the return values using the following code:
            Process process = Runtime.getRuntime().exec("epidemic.exe");
            //process.waitFor();
            System.out.println("....");

            InputStream in = process.getInputStream();  // To read process standard output
            InputStream err = process.getErrorStream(); // To read process error output

            while (process.isAlive()) {
                while (in.available() > 0 || err.available() > 0) {
                    if (in.available() > 0) {
                        System.out.print((char)in.read()); // You might wanna echo it to your console to see progress
                    }
                    if (err.available() > 0) {
                        err.read(); // You might wanna echo it to your console to see progress
                    }
                }

                Thread.sleep(1);
            }

           System.out.println("....");

EDIT: Based on the proposed changes I re-change my code. Again, it doesn't seem print the returned values. If this code is ok, how could I check if the executable indeed return values? 

A:

Your while loop tries to read whole lines from the standard output of the started process.
I highlighted the potential problems. If the process does not write a whole line, or it writes to its standard error for example, reader.readLine() will block forever.
Also note that a process has 2 output streams: standard output and standard error. Both has a buffer, and if any of them gets filled without you reading it, the process will be blocked when trying to write more outputs.
To ensure the process does not get blocked, you have to read both of its output streams, here is an example how to do it:
InputStream in = process.getInputStream();  // To read process standard output
InputStream err = process.getErrorStream(); // To read process error output

while (proc.isAlive()) {
    while (in.available() > 0 || err.available() > 0) {
        if (in.available() > 0)
            in.read(); // You might wanna echo it to your console to see progress

        if (err.available() > 0)
            err.read(); // You might wanna echo it to your console to see progress
    }

    Thread.sleep(1);
}

If you want to print the data read from the output streams of the process, you can do it like this:
System.out.print((char)in.read()); // read() returns int, convert it to char

