When attempting to use IO.popen to send SQL to a mysql child process, I noticed the child processes were getting forcibly killed when the IO object is closed.
Looking inside ShellLauncher.POpenProcess, I tried inserting a Process#waitFor instead of RubyIO.obliterateProcess (which uses Process#destroy).
This works well except that there appears to be a JDK bug on OS X where the child process's stdout file descriptor is not closed when the Java process's InputStream is closed. Thus the following program hangs.
To work around this, POpenProcess will only use child.waitFor if the process is opened for writing.