drain filehandle before waiting for subprocess to finish