[GH-ISSUE #7820] Instant closure when using shell input with piped output. #30763

Open
opened 2026-04-22 10:40:19 -05:00 by GiteaMirror · 6 comments
Owner

Originally created by @WyvernDotRed on GitHub (Nov 24, 2024).
Original GitHub issue: https://github.com/ollama/ollama/issues/7820

Originally assigned to: @dhiltgen on GitHub.

What is the issue?

When running ollama run [model] | cat or ollama run [model] > [file], ollama now closes immediately and does not accept any manual input.
ollama run [model] still functions as expected.

While cat | ollama run [model] ... seems to be the workaround, this requires entering ^d to have the input processed.
Thus closing the input stream and also ollama as a result, expected in this case since input was explicitly closed.
Additionally, thanks to pull 416, this removes the ability to queue or follow up with further prompts.

This regression seems specific to 0.4.4.
After downgrading to 0.4.3 or 0.4.2, ollama functions as I expect.
I have not tested older versions and will stick to version 0.4.3 for the time being.

The purpose of the above syntax being to use the ability of the chat functionality for to enter multiple prompts while processing the output by a further script.
Though this will be covered in a following feature request and is only tangentially related to this regression.

Thank you for your time, have a nice rest of your day!

OS

Linux

GPU

AMD

CPU

AMD

Ollama version

0.4.4

Originally created by @WyvernDotRed on GitHub (Nov 24, 2024). Original GitHub issue: https://github.com/ollama/ollama/issues/7820 Originally assigned to: @dhiltgen on GitHub. ### What is the issue? When running `ollama run [model] | cat` or `ollama run [model] > [file]`, ollama now closes immediately and does not accept any manual input. `ollama run [model]` still functions as expected. While `cat | ollama run [model] ...` seems to be the workaround, this requires entering ^d to have the input processed. Thus closing the input stream and also ollama as a result, expected in this case since input was explicitly closed. Additionally, thanks to [pull 416](https://github.com/ollama/ollama/pull/416), this removes the ability to queue or follow up with further prompts. This regression seems specific to 0.4.4. After downgrading to 0.4.3 or 0.4.2, ollama functions as I expect. I have not tested older versions and will stick to version 0.4.3 for the time being. The purpose of the above syntax being to use the ability of the chat functionality for to enter multiple prompts while processing the output by a further script. Though this will be covered in a following feature request and is only tangentially related to this regression. Thank you for your time, have a nice rest of your day! ### OS Linux ### GPU AMD ### CPU AMD ### Ollama version 0.4.4
GiteaMirror added the needs more infobug labels 2026-04-22 10:40:19 -05:00
Author
Owner

@rick-github commented on GitHub (Nov 24, 2024):

Likely a function of https://github.com/ollama/ollama/pull/7360.

You can work around this by using a helper function:

$ faketty() { script -qfc "$(printf "%q " "$@")" /dev/null ; }
$ faketty ollama run qwen2.5:0.5b | tee /dev/stderr | wc
>>> hello
Hello! How can I help you today?

>>> /bye
      4      22     359
<!-- gh-comment-id:2496152849 --> @rick-github commented on GitHub (Nov 24, 2024): Likely a function of https://github.com/ollama/ollama/pull/7360. You can work around this by using a helper function: ```console $ faketty() { script -qfc "$(printf "%q " "$@")" /dev/null ; } $ faketty ollama run qwen2.5:0.5b | tee /dev/stderr | wc >>> hello Hello! How can I help you today? >>> /bye 4 22 359 ```
Author
Owner

@dhiltgen commented on GitHub (Nov 24, 2024):

@WyvernDotRed this change in behavior was intentional to fix bugs others have faced while scripting ollama. It's unusual to have an interactive CLI that works when stdout is redirected. If you feed input in via pipe it should work. For example echo "hello" | ollama run orca-mini > out.txt

Can you help us understand your use-case where you want an interactive behavior without the output being presented back to the user?

<!-- gh-comment-id:2496197467 --> @dhiltgen commented on GitHub (Nov 24, 2024): @WyvernDotRed this change in behavior was intentional to fix bugs others have faced while scripting ollama. It's unusual to have an interactive CLI that works when stdout is redirected. If you feed input in via pipe it should work. For example `echo "hello" | ollama run orca-mini > out.txt` Can you help us understand your use-case where you want an interactive behavior without the output being presented back to the user?
Author
Owner

@WyvernDotRed commented on GitHub (Nov 24, 2024):

@WyvernDotRed this change in behavior was intentional to fix bugs others have faced while scripting ollama. It's unusual to have an interactive CLI that works when stdout is redirected. If you feed input in via pipe it should work. For example echo "hello" | ollama run orca-mini > out.txt

Can you help us understand your use-case where you want an interactive behavior without the output being presented back to the user?

You can find this in the feature request I made before I saw your reply.
In short, queueing up multiple prompts for one session in a script.
My specific use-case being automating multiple questions for models which restrict their output length.
As mentioned in that longer post, I am running against the single prompt restriction imposed in pull 416 while doing so and need excessive workarounds to make the chat dialogue work for this.

edit: To clarify, the issue at hand is STDIN getting immediately closed without an explicit EOF.
This paired with non-interactive STDIN removing the ability to have multiple prompts, but that is out of the scope of this specific issue.

<!-- gh-comment-id:2496236392 --> @WyvernDotRed commented on GitHub (Nov 24, 2024): > @WyvernDotRed this change in behavior was intentional to fix bugs others have faced while scripting ollama. It's unusual to have an interactive CLI that works when stdout is redirected. If you feed input in via pipe it should work. For example `echo "hello" | ollama run orca-mini > out.txt` > > Can you help us understand your use-case where you want an interactive behavior without the output being presented back to the user? You can find this in the [feature request I made](https://github.com/ollama/ollama/issues/7823) before I saw your reply. In short, queueing up multiple prompts for one session in a script. My specific use-case being automating multiple questions for models which restrict their output length. As mentioned in that longer post, I am running against the single prompt restriction imposed in [pull 416](https://github.com/ollama/ollama/pull/416) while doing so and need excessive workarounds to make the chat dialogue work for this. edit: To clarify, the issue at hand is STDIN getting immediately closed without an explicit EOF. This paired with non-interactive STDIN removing the ability to have multiple prompts, but that is out of the scope of this specific issue.
Author
Owner

@dhiltgen commented on GitHub (Nov 24, 2024):

automating multiple questions for models which restrict their output length.

Can you clarify, is each prompt/response independent, or are you relying on the prior context (both prompt and response)?

It feels like your use-case may be better served by scripting/coding to the API instead of using the CLI.

<!-- gh-comment-id:2496255414 --> @dhiltgen commented on GitHub (Nov 24, 2024): > automating multiple questions for models which restrict their output length. Can you clarify, is each prompt/response independent, or are you relying on the prior context (both prompt and response)? It feels like your use-case may be better served by scripting/coding to the API instead of using the CLI.
Author
Owner

@WyvernDotRed commented on GitHub (Nov 24, 2024):

The behaviour of ollama run closing without an EOF still is unexpected.
E.g. running cat or another standard utility in a terminal, the expected behaviour of the shell forwarding input to STDIN and both outputs being mixed occurs.
This until ^d is entered, explicitly sending an EOF and signalling that the input has ended.

If this behaviour were consistent, it would allow ollama run [model] | tee [file] to store the output while interacting with the model manually, to name an example.
My specific use-case here being not to have to manually copy-paste and risk cutting off some text in an educational assignment in comparing AI model output.

I consider this difference compared to other shell programs as the scope of this issue, but attempted to provide some further context.
Shells like Bash can be weird and unintuitive around data streams, but attempting to improve on this by making a program respond differently ends up making the experience of scripting worse, in my opinion.

The further discussion about use-cases of multiple prompts within the same context is better left to the feature request.
So my further reply is at comment 2496320009.

<!-- gh-comment-id:2496320635 --> @WyvernDotRed commented on GitHub (Nov 24, 2024): The behaviour of `ollama run` closing without an EOF still is unexpected. E.g. running `cat` or another standard utility in a terminal, the expected behaviour of the shell forwarding input to STDIN and both outputs being mixed occurs. This until ^d is entered, explicitly sending an EOF and signalling that the input has ended. If this behaviour were consistent, it would allow `ollama run [model] | tee [file]` to store the output while interacting with the model manually, to name an example. My specific use-case here being not to have to manually copy-paste and risk cutting off some text in an educational assignment in comparing AI model output. I consider this difference compared to other shell programs as the scope of this issue, but attempted to provide some further context. Shells like Bash can be weird and unintuitive around data streams, but attempting to improve on this by making a program respond differently ends up making the experience of scripting worse, in my opinion. The further discussion about use-cases of multiple prompts within the same context is better left to the [feature request](https://github.com/ollama/ollama/issues/7823). So my further reply is at [comment 2496320009](https://github.com/ollama/ollama/issues/7823#issuecomment-2496320009).
Author
Owner

@fxmbsw7 commented on GitHub (Dec 10, 2024):

i tried script commands -B log
no matter of -E echo never | always | auto
input gets send multiple times to log file

<!-- gh-comment-id:2532893512 --> @fxmbsw7 commented on GitHub (Dec 10, 2024): i tried script commands -B log no matter of -E echo never | always | auto input gets send multiple times to log file
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#30763