From d88972ea48cfec20ebba6e0a86a825fca3ecb193 Mon Sep 17 00:00:00 2001 From: Daniel Hiltgen Date: Fri, 22 Nov 2024 08:04:54 -0800 Subject: [PATCH] Be quiet when redirecting output (#7360) This avoids emitting the progress indicators to stderr, and the interactive prompts to the output file or pipe. Running "ollama run model > out.txt" now exits immediately, and "echo hello | ollama run model > out.txt" produces zero stderr output and a typical response in out.txt --- cmd/cmd.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmd/cmd.go b/cmd/cmd.go index 91819c8e..97e821c7 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -456,6 +456,10 @@ func RunHandler(cmd *cobra.Command, args []string) error { if len(prompts) > 0 { interactive = false } + // Be quiet if we're redirecting to a pipe or file + if !term.IsTerminal(int(os.Stdout.Fd())) { + interactive = false + } nowrap, err := cmd.Flags().GetBool("nowordwrap") if err != nil {