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
This commit is contained in:
Daniel Hiltgen 2024-11-22 08:04:54 -08:00 committed by GitHub
parent 25c9339e2d
commit d88972ea48
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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 {