0

I am in the process of making a GUI in Javafx for a Java based command line tool the one of my predecessors had made. The command line tool is a 2 step tool, first you run the program using a specific set of configurations after which the command line input is required to quit out of the program or for additional analyses. I am using the following block of code to run the first half of the command-line tool:

        button = new Button("Run Proteinarium");
    button.setOnAction( e -> {System.out.println("Running Proteinarium");
    String command = "java -jar Proteinarium-master\\example\\Proteinarium.jar config=Proteinarium-master\\example\\config_SIM.txt";
    try {
        Process process = Runtime.getRuntime().exec(command);

        BufferedReader reader = new BufferedReader(
                new InputStreamReader(process.getInputStream()));
        String line;
        while ((line = reader.readLine()) != null) {
            System.out.println(line);
        }

        reader.close();

    } catch (IOException ex) {
        ex.printStackTrace();
    }

    }
    );

However, after click on the button while the first half of the command-line tool does run, the GUI stops responding. I believe this is likely due to the second-half of the command-line tool requiring additional input in the command Terminal. Any ideas for how to fix this?

I am running this on Windows 10.

Anthony
  • 103
  • 5
  • 2
    Personally, since it's an open-source project, I'd think it'd be better to just replace the CLI, e.g., https://github.com/Armanious/Proteinarium/blob/master/src/org/armanious/network/analysis/Entry.java. – Dave Newton May 22 '20 at 20:49
  • [mcve] please .. – kleopatra May 22 '20 at 21:00
  • 4
    `reader.readLine()` will block execution until there is data available, and the loop won't exit until the end of the stream (which happens when the process finishes). Since you're running this on the FX Application Thread, you block that thread, and it can't render the UI or respond to user events. To do this, you would need to read the output of the process in a background thread. As mentioned in another comment, though, this is just completely the wrong approach; reuse the non-CLI parts of the existing codebase in a UI application. – James_D May 22 '20 at 21:01

0 Answers0