Repository navigation
IO and redirection overhaul - #11934
Merged
Merged
Conversation
Contributor
|
wow, that's some great performance gains! nice work! |
Member
|
How relevant is this part after #12120 or how much additional complexity do we need to handle?
|
Member
Author
|
Still relevant, the overrides allow a more efficient implementation (this is part of how the speedup is obtained). The overrides are also opt-in, so most commands don't need to worry about it. |
Contributor
|
FYI to people watching, we agreed yesterday to land this as soon as @IanManske cleans up a few minor things. |
sholderbach
reviewed
Mar 14, 2024
Contributor
|
Congrats! I'm excited about this one |
This was referenced Mar 26, 2024
2 tasks done
IanManske
added a commit
that referenced
this pull request
Apr 25, 2024
# Description Removes the `run-external` flags that were deprecated in 0.92.0 with #11934.
This was referenced Jul 11, 2026
Kissaki
added a commit
to Kissaki/nushell.github.io
that referenced
this pull request
Jul 11, 2026
The 0.92.0 release notes document the behavior previously documented here. Update to current behavior. The 0.92.0 release notes > File redirections (`o>`, `e>`, `o+e>`, etc.) now apply to all ***external*** commands inside an expression. I searched this repository for ` e> `, ` o> `, ` err> `, ` out> `, `subexpression`, `piping`. I was not able to identify release notes that document changed behavior after 0.92.0, and checked the [0.92.0 PR](nushell/nushell#11934) for linked followups or comments. Resolves nushell#2152 Resolves nushell/nushell#17604
fdncred
pushed a commit
to nushell/nushell.github.io
that referenced
this pull request
Jul 11, 2026
The 0.92.0 release notes document the behavior previously documented here. Update to current behavior. The 0.92.0 release notes > File redirections (`o>`, `e>`, `o+e>`, etc.) now apply to all ***external*** commands inside an expression. I searched this repository for ` e> `, ` o> `, ` err> `, ` out> `, `subexpression`, `piping`. I was not able to identify release notes that document changed behavior after 0.92.0, and checked the [0.92.0 PR](nushell/nushell#11934) for linked followups or comments. Resolves #2152 Resolves nushell/nushell#17604
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
The PR overhauls how IO redirection is handled, allowing more explicit and fine-grain control over
stdoutandstderroutput as well as more efficient IO and piping.To summarize the changes in this PR:
IoStreamtype to indicate the intended destination for a pipeline element'sstdoutandstderr.stdoutandstderrIoStreams are stored in theStackand to avoid adding 6 additional arguments to every eval function andCommand::run. Thestdoutandstderrstreams can be temporarily overwritten through functions onStackand these functions will return a guard that restores the originalstdoutandstderrwhen dropped.PipelineElementas aOption<Redirection>field instead of having multiple differentPipelineElementenum variants for each kind of redirection. This required changes to the parser, mainly inlite_parser.rs.Commands can also set aIoStreamoverride/redirection which will apply to the previous command in the pipeline. This is used, for example, inignoreto allow the previous external command to have its stdout redirected toStdio::null()at spawn time. In contrast, the current implementation has to create an os pipe and manually consume the output on nushell's side. File and pipe redirections (o>,e>,e>|, etc.) have precedence over overrides from commands.This PR improves piping and IO speed, partially addressing #10763. Using the
throughputcommand from that issue, this PR gives the following speedup on my setup for the commands below:throughput o> /dev/nullthroughput | ignorethroughput | nullthroughput | rg 'x'(throughput) | rg 'x'(Numbers above are the median samples for throughput)
This PR also paves the way to refactor our
ExternalStreamhandling in the various commands. For example, this PR already fixes the following code:This returns an empty list on 0.90.1 and returns a highlighted "hello world" on this PR.
Since the
stdoutandstderrIoStreams are available to commands when they are run, then this unlocks the potential for more convenient behavior. E.g., thefindcommand can disable its ansi highlighting if it detects that the outputIoStreamis not the terminal. Knowing the output streams will also allow background job output to be redirected more easily and efficiently.User-Facing Changes
External commands returned from closures will be collected (in most cases):
This gives
["a", "a"]on this PR, whereas this used to print "a\na\n" and then return an empty list.This gives
["", ""]and prints "a\na\n" to stderr, whereas this used to return an empty list and print "a\na\n" to stderr.Trailing new lines are always trimmed for external commands when piping into internal commands or collecting it as a value. (Failure to decode the output as utf-8 will keep the trailing newline for the last binary value.) In the current nushell version, the following three code snippets differ only in parenthesis placement, but they all also have different outputs:
1..2 | each { ^echo a }1..2 | each { (^echo a) }1..2 | (each { ^echo a })But in this PR, the above snippets will all have the same output:
All existing flags on
run-externalare now deprecated.File redirections now apply to all commands inside a code block:
This gives "a\nb\n" in
test.outand prints nothing. The same result would happen when printing to stdout and using ao>file redirection.External command output will (almost) never be ignored, and ignoring output must be explicit now:
This prints "a\nb\n", whereas this used to print only "b\n". This only applies to external commands; values and internal commands not in return position will not print anything (e.g.,
(echo a; echo b)still only prints "b").completenow always captures stderr (dois not necessary).After Submitting
The language guide and other documentation will need to be updated.