java - Condition for when outside program closes -


i have program when prompted, opens external editor (currently hard coded sublime). user type whatever they're typing in editor, save temp file, , close editor. when user closes editor, want contents of temp file displayed in program. main concern creating conditional can tell when editor has been closed. can windowlistener used in reference outside program being launched? here code far: (note: use runtime due compatibility issue desktop , current version of gnome. run on linux.)

private cachedtextinfo cti; private file temp = file.createtempfile("tempfile",".tmp");   try{     thetext.settext(cti.initialtext);     string currenttext = thetext.gettext();     bufferedwriter bw = new bufferedwriter(new filewriter(temp));     bw.write(currenttext);     bw.close();     runtime.getruntime().exec("subl "+ temp.getabsolutepath());     //when editor closes, display tmp contents         }catch(ioexception e) {             e.printstacktrace();         }  

thank , let me know if require additional information.

runtime.exec() returns process instance, has waitfor() method. can do

process p = runtime.getruntime().exec("subl "+ temp.getabsolutepath()); try {     p.waitfor();     // display tmp contents... } catch (interruptedexception exc) {     // thread interrupted waiting process complete... } 

Comments