child_process.spawn in Node.js versions prior to 0.7 use the exit event to signal that the child process has finished; newer versions use the close event. Listening to the exit event in version >= 0.7 will result in occasional data loss if the exit event fires before close.
spawn ends on the close event in node version greater than 7
Listen for close event rather than exit
Listening to the exit event leads to occasional data loss.