add check for closed system_stream before os.dup2