Using instructions in Open a text file in the default text editor… via Java?, I am opening an external file editor to edit a file like this;
try {
File temp = File.createTempFile("commit-", ".tmp");
if (System.getProperty("os.name").toLowerCase().contains("windows")) {
String cmd = "rundll32 url.dll,FileProtocolHandler " + temp.getCanonicalPath();
Process p = Runtime.getRuntime().exec(cmd);
p.waitFor();
System.out.println("Reached this line");
} else {
Desktop.getDesktop().edit(temp);
}
} catch (IOException|InterruptedException e) {
System.err.println(e.getMessage());
}
I don't want my program to continue executing until that editor exits. My solution was to use waitfor()
, however, I am seeing the message Reached this line
while external application -- "notepad++" in this case -- still running. I am running windows 7, netbeans 7.3.1 and jdk 1.7.
Also, I have no idea how to do it in else block.