Honestly to I guess the Answer given above is correct.
Just use another thread inside the button event so your Java programs main thread wont have to wait till the thing finishes and could prevent the UI from freezing.
Create a Thread
public class MyRunnable implements Runnable {
private String commandParameters = "";
// Just Creating a Constructor
public MyRunnable(String cmd)
{
this.commandParameters = cmd;
}
public void run()
{
try
{
Runtime runtime = Runtime.getRuntime();
// Custom command parameters can be passed through the constructor.
Process process = runtime.exec("python " + commandParameters);
process.getOutputStream();
}
catch(Exception e)
{
// Some exception to be caught..
}
}
}
And in Your Button Event do this
yourBtn.setOnAction(event -> {
try{
Thread thread = new Thread(new MyRunnable("command parameter string"));
thread.start();
}
catch(Exception e)
{
// Some Expection..
}
});
Now your main thread you not freeze or wait for the command execution to complete.
Hope this solves the issue. if you want to pass some variable values to the "python command" just make you of a constructor while creating MyRunnable Class and pass the it as parameters to the constructor of the MyRunnable Class.
Now this will run a new thread when you click the button. That would not mess with your main UI thread.