Handle stdout closing suddenly