What is the typical design for a program (such as a command line utility) to spawn an external editor and read back changes to the file? Many command line utilities do this. For example, svn commit launches an external editor to get the comment if it is run without -c.
Some options I have considered are:
- Poll a temp file file, waiting for the timestamp to change, but this would be limited to a single save.
- Register with the operating system to be notified of changes to a temp file, but this would would be platform dependent, which I’d like to avoid.
- Monitor the spawned process, waiting for it to terminate, but I’m not sure how this would work for editors such as TextMate and TextWrangler that typically have long-lived processes.
- Interact with the spawned process by stdin and stdout, but I’m not clear on the details of how/if this could work.
Hopefully the solution is platform independent. For the record my platform is the JVM on OS X.
P.S. Any advice on appropriate tags for this question?
If you launch a process through Java (Runtime.exec), you get a Process object back, which has a waitFor() method that will tell you when the process is complete.
Just run vi or nano or whatever via that, and once it exits, you can read the file.