How should i close an opened browser window using java code. I have found a way to first find the process then end that process. Is there any better way? I have opened the brows
You can put it in a Process
and kill that.
Runtime runtime = Runtime.getRuntime();
Process p = runtime.exec("/usr/bin/firefox -new-window " + url);
p.destroy();
-- update --
You should execute your command with a String array
Process p = Runtime.getRuntime().exec(new String[]{
"/usr/bin/firefox",
"-new-window", url
});
This is less prone to errors: Java execute a command with a space in the pathname
Or use ProcessBuilder
: ProcessBuilder Documentation