diff --git a/RA3MP3Playback.pyw b/RA3MP3Playback.pyw index 5aed971..e20922a 100644 --- a/RA3MP3Playback.pyw +++ b/RA3MP3Playback.pyw @@ -647,12 +647,23 @@ def game_launch(gameargs): else: master_fd, slave_fd = pty.openpty() + # Close all file descriptors except the pty + # This prevents inheritance of file manager's stdin/stdout + max_fd = 1024 # Reasonable upper limit + for fd in range(3, max_fd): + try: + os.close(fd) + except OSError: + pass + pty_proc = subprocess.Popen( [game_exe, "+set", "ttycon", "1"] + gameargs, stdin=slave_fd, stdout=slave_fd, stderr=slave_fd, - close_fds=True + close_fds=True, + # Don't let the child process be affected by parent's terminal + preexec_fn=os.setsid if hasattr(os, 'setsid') else None ) os.close(slave_fd)