I have a executable which I need to execute from a JSF application running on Payara Server when a user submits a form. I have written a CDI View Scoped Bean which has a method to execute the program. The executable outputs in standard console and I require to read & parse the output from standard input and display it to the user. The executable is not providing correct output but if the same methid is executed from a standalone Java program, it is giving the proper output.

@Named
@ViewScoped
public class TestBean implements Serializable{
public void compute(){
    String executable = "./xyz.exe";
    String parameter1 = "90.0"; // This input is coming from a user through a form
    String parameter2 = "13.0";

    File executeDirectory = "/path/to/executable";
    ProcessBuilder pb = new ProcessBuilder(executable, parameter1, parameter2);
    pb.directory(executeDirectory);
    Process p = pb.start();
    BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
    String line;
    while((line = reader.readLine())!=null){
        System.out.println(line); // I shall parse later and render the output to the user
    }
}
}

The issue is that if I run the same program as a standalone, the executable prints the complete output but running as a Bean, the executable is giving output of 1st and last line and intermediate output data is not printed.

0

There are 0 best solutions below