Repository navigation
fix: send a script's stderr through its redirects - #199
Merged
Merged
Conversation
A script run with `sh file`, `lash file` or `./file` lost its stderr. In Shell::run the stderr was dropped, so `sh s.sh 2>e` left e empty and Output.stderr empty. In the CLI both streams went straight to the terminal, so `>o`, `2>e` and pipes had no effect. The script now runs with its output captured, as a function in a pipeline does, and its stdout and stderr go to the stage's fd 1 and fd 2 when it ends. So redirects and pipes apply in both modes. The output is no longer streamed in the CLI. Captured output over the limit now reports the limit once for each run of over-limit writes, instead of once for each write.
10 tasks done
kevin-orellana
previously approved these changes
Nov 4, 2026
# Conflicts: # src/os.rs
kevin-orellana
approved these changes
Nov 5, 2026
This was referenced Nov 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
A script run with
sh file(orlash file, or./filewith a shebang) lost its stderr. Throughrun, which Python and Node use, the script's stderr just disappeared, and in the CLI it was the other way around: both streams went straight to the terminal, so redirects and even pipes had no effect.Now the script's output is collected while it runs, the same way a function inside a pipeline already works, and when it finishes it goes wherever that command's redirects point, so
2> err,2>&1, pipes and$(…)behave like bash in both modes. Two visible changes: in the CLI a script's output shows up when it ends instead of streaming, and with2>&1all stdout comes before all stderr; and the output limit message now shows once for each stretch of over-limit writes instead of once per write, because with stderr forwarded that became thousands of lines.Evidence of how this is fixed in Box
Strands Box carries a vendored copy of Shell and partly fixed this: when a script runs as a pipeline stage, it forwards the script's stdout and stderr after the script ends, which came with another fix (UPSTREAM.md note). That works through
runbut the CLI is still broken there, and 6 of this PR's 9 tests pass on it.Related Issues
None.
Documentation PR
None.
Type of Change
Bug fix
Testing
I checked each case against bash, the new tests fail without the fix, and the Rust, Python and Node suites pass. I broke the limit dedupe on purpose and its test caught it. Things I noticed but left alone: a script past a timeout now prints the timeout message twice, in the CLI
x=$(sh s.sh)doesn't show the script's stderr (same as any other$(…)in the CLI today), and a script can't read piped stdin. This PR and #196 both add a small helper at the same spot insrc/os.rs, so whichever lands second needs a trivial rebase.cargo test --workspace --all-targets,pytest tests/python,npm test)cargo fmtandcargo clippyChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.