@@ -955,7 +955,7 @@ namespace vix::commands::RunCommand::detail
955955 ::kill (pid, sig);
956956 }
957957
958- void child_exec_shell (const std::string &cmd, int masterFd, int slaveFd, bool useSan)
958+ void child_exec_shell (const std::string &cmd, int masterFd, int slaveFd, bool useSan, bool inheritParentStdin )
959959 {
960960 struct sigaction saChild{};
961961 saChild.sa_handler = SIG_DFL;
@@ -996,7 +996,9 @@ namespace vix::commands::RunCommand::detail
996996
997997 ::close (masterFd);
998998
999- ::dup2 (slaveFd, STDIN_FILENO);
999+ if (!inheritParentStdin)
1000+ ::dup2 (slaveFd, STDIN_FILENO);
1001+
10001002 ::dup2 (slaveFd, STDOUT_FILENO);
10011003 ::dup2 (slaveFd, STDERR_FILENO);
10021004
@@ -1119,15 +1121,21 @@ namespace vix::commands::RunCommand::detail
11191121 return result;
11201122 }
11211123
1124+ const bool stdinIsTty = (::isatty (STDIN_FILENO) != 0 );
1125+ const bool inheritParentStdin = passthroughRuntime && !stdinIsTty;
1126+ bool forwardStdin = passthroughRuntime && stdinIsTty;
1127+
11221128 if (pid == 0 )
1123- child_exec_shell (cmd, pty.masterFd , pty.slaveFd , useSan);
1129+ child_exec_shell (
1130+ cmd,
1131+ pty.masterFd ,
1132+ pty.slaveFd ,
1133+ useSan,
1134+ inheritParentStdin);
11241135
11251136 close_safe (pty.slaveFd );
11261137 ::setpgid (pid, pid);
11271138
1128- const bool forwardStdin =
1129- passthroughRuntime && (::isatty (STDIN_FILENO) != 0 );
1130-
11311139 bool spinnerActive = false ;
11321140 std::size_t frameIndex = 0 ;
11331141
@@ -1281,10 +1289,15 @@ namespace vix::commands::RunCommand::detail
12811289 {
12821290 char inbuf[4096 ];
12831291 const ssize_t n = ::read (STDIN_FILENO, inbuf, sizeof (inbuf));
1292+
12841293 if (n > 0 )
12851294 {
12861295 write_all (pty.masterFd , inbuf, static_cast <std::size_t >(n));
12871296 }
1297+ else if (n == 0 )
1298+ {
1299+ forwardStdin = false ;
1300+ }
12881301 }
12891302
12901303 if (pty.masterFd >= 0 && FD_ISSET (pty.masterFd , &fds))
0 commit comments