I'm experiencing a very weird behavior from JavaFX. It is related to Why are Runtime.getRuntime().exec and ProcessBuilder starting my second jar application after the first one exits? that wasn't exactly answered. The proposed workaround is sadly not applicable to my needs.
The behavior arises when starting a process either through ProcessBuilder or Runtime.exec() from a JavaFX application specifically. Here's a test code:
package testingfx;
import java.io.IOException;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class TestingFX extends Application {
@Override
public void start(Stage stage) {
StackPane root = new StackPane();
Scene scene = new Scene(root, 300, 250);
stage.setScene(scene);
stage.show();
ProcessBuilder builder;
builder = new ProcessBuilder(
"C:\\Program Files\\MPC-HC\\mpc-hc64.exe");
try {
builder.start();
} catch (IOException x) {
System.err.println(x);
}
}
public static void main(String[] args) {
launch(args);
}
}
If you happen to have MPC-HC installed on your computer you will see it being executed as soon as the application starts, as expected. However, if I now replace the parameter with "C:\\Program Files\\VideoLAN\\VLC\\vlc.exe"
, VLC will only execute when the application is closed.
I was unable to find any information on why this is happening. The same code in Swing is working as expected, so what give? Ideas are most welcome.