diff --git a/internal/cmd/project_loader.go b/internal/cmd/project_loader.go index 800bc669..50a8cfc2 100644 --- a/internal/cmd/project_loader.go +++ b/internal/cmd/project_loader.go @@ -23,9 +23,9 @@ type projectLoader struct { } func newProjectLoader(cmd *cobra.Command, allowUnknown, allowUnnamed bool) (*projectLoader, error) { - fd := os.Stdout.Fd() + ofd := os.Stdout.Fd() - if int(fd) < 0 { + if int(ofd) < 0 { return nil, fmt.Errorf("invalid file descriptor due to restricted environments, redirected standard output, system configuration issues, or testing/simulation setups") } @@ -35,7 +35,7 @@ func newProjectLoader(cmd *cobra.Command, allowUnknown, allowUnnamed bool) (*pro ctx: cmd.Context(), w: cmd.OutOrStdout(), r: cmd.InOrStdin(), - isTerminal: isTerminal(fd), + isTerminal: isTerminal(ofd) && isTerminal(os.Stdin.Fd()), }, nil } diff --git a/internal/cmd/run.go b/internal/cmd/run.go index 541ddad9..5f912d06 100644 --- a/internal/cmd/run.go +++ b/internal/cmd/run.go @@ -1,6 +1,7 @@ package cmd import ( + "bytes" "context" "fmt" "io" @@ -182,10 +183,17 @@ func runCmd() *cobra.Command { return err } + // non-tty fails on linux otherwise + var stdin io.Reader + stdin = bytes.NewBuffer([]byte{}) + if isTerminal(os.Stdout.Fd()) { + stdin = cmd.InOrStdin() + } + runnerOpts = append( runnerOpts, client.WithinShellMaybe(), - client.WithStdin(cmd.InOrStdin()), + client.WithStdin(stdin), client.WithStdout(cmd.OutOrStdout()), client.WithStderr(cmd.ErrOrStderr()), client.WithProject(proj), diff --git a/internal/cmd/tui_common.go b/internal/cmd/tui_common.go index bc7226d2..c99524bd 100644 --- a/internal/cmd/tui_common.go +++ b/internal/cmd/tui_common.go @@ -26,7 +26,7 @@ func newProgramWithOutputs(output io.Writer, input io.Reader, model tea.Model, o opts = append(opts, tea.WithOutput(output)) } - if input != nil { + if input != nil && isTerminal(os.Stdin.Fd()) { opts = append(opts, tea.WithInput(input)) }