This ensures that all the available data on standard out and standard error has been read before the terminate handler calls the JavaScript callback. Without this synchronization the command panel specs occasionally fail.