Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

run-external --redirect-stderr is confusing / there's no way to operate on stderr? #10944

Closed
gandalf3 opened this issue Nov 4, 2023 · 1 comment · Fixed by #11708
Closed
Labels
needs-triage An issue that hasn't had any proper look redirection-pipe All related to redirection to files or more complex pipelines with STDERR
Milestone

Comments

@gandalf3
Copy link

gandalf3 commented Nov 4, 2023

Describe the bug

the documentation here says

--redirect-stderr, -: redirect stderr to the pipeline

which lead me to believe this would work

>  run-external --redirect-stderr "python" "-c" "import sys; print('hello on stderr', file=sys.stderr)" | inspect
Error: nu::shell::pipeline_mismatch

  × Pipeline empty.
   ╭─[entry #1:1:1]
 1 │  run-external --redirect-stderr "python" "-c" "import sys; print('hello on stderr', file=sys.stderr)" | inspect
   ·                                                                                                         ───┬───
   ·                                                                                                            ╰── no input value was piped in
   ╰────

if im understanding right, --redirect stderr does not mean "redirect stderr to the pipeline" (what i assumed to mean "the next command's stdin"), it currently means "redirect stderr to the stderr stream in the pipeline", which is ignored by most (all?) nu commands, and as far as i can tell from #4396, exists purely for use with capture or redirects.

trying to redirect stderr to stdout as follows kind of works, but rather than going into nu's pipeline as expected, it is written to the terminal.

> run-external --redirect-stderr "python" "-c" "import sys; print('hello on stderr', file=sys.stderr)" err> /dev/stdout | inspect
hello on stderr
Error: nu::shell::pipeline_mismatch

  × Pipeline empty.
   ╭─[entry #27:1:1]
 1 │ run-external --redirect-stderr "python" "-c" "import sys; print('hello on stderr', file=sys.stderr)" err> /dev/stdout | inspect
   ·                                                                                                                         ───┬───
   ·                                                                                                                            ╰── no input value was piped in
   ╰────

How to reproduce

run-external --redirect-stderr "python" "-c" "import sys; print('hello on stderr', file=sys.stderr)" | inspect

Expected behavior

I expected nu to have an easy way to read and operate on stderr, and in general manipulate io streams freely, since it is common functionality in posix/bash/zsh etc.

Screenshots

No response

Configuration

key value
version 0.86.0
branch makepkg
commit_hash 5d8763e
build_os linux-x86_64
build_target x86_64-unknown-linux-gnu
rust_version rustc 1.73.0 (cc66ad468 2023-10-03) (Arch Linux rust 1:1.73.0-1)
cargo_version cargo 1.73.0
build_time 2023-10-18 08:45:09 +00:00
build_rust_channel release
allocator mimalloc
features dataframe, default, extra, sqlite, trash, which, zip
installed_plugins

Additional context

No response

@gandalf3 gandalf3 added the needs-triage An issue that hasn't had any proper look label Nov 4, 2023
@amtoine amtoine added the redirection-pipe All related to redirection to files or more complex pipelines with STDERR label Nov 4, 2023
@MarikaChlebowska
Copy link
Contributor

I agree, I think redirect-stderr should simply move stderr of the command to stdout so next command can use it as an input. I'm not sure if we should keep stderr of the run-external empty or keep it as it is right now. If someone from the maintainers gives me a green light I think I can change it.

@hustcer hustcer added this to the v0.91.0 milestone Feb 9, 2024
dmatos2012 pushed a commit to dmatos2012/nushell that referenced this issue Feb 20, 2024
# Description
Close: nushell#9673
Close: nushell#8277
Close: nushell#10944

This pr introduces the following syntax:
1. `e>|`, pipe stderr to next command. Example: `$env.FOO=bar nu
--testbin echo_env_stderr FOO e>| str length`
2. `o+e>|` and `e+o>|`, pipe both stdout and stderr to next command,
example: `$env.FOO=bar nu --testbin echo_env_mixed out-err FOO FOO e+o>|
str length`

Note: it only works for external commands. ~There is no different for
internal commands, that is, the following three commands do the same
things:~ Edit: it raises errors if we want to pipes for internal
commands
``` 
❯ ls e>| str length
Error:   × `e>|` only works with external streams
   ╭─[entry nushell#1:1:1]
 1 │ ls e>| str length
   ·    ─┬─
   ·     ╰── `e>|` only works on external streams
   ╰────

❯ ls e+o>| str length
Error:   × `o+e>|` only works with external streams
   ╭─[entry nushell#2:1:1]
 1 │ ls e+o>| str length
   ·    ──┬──
   ·      ╰── `o+e>|` only works on external streams
   ╰────
```

This can help us to avoid some strange issues like the following:

`$env.FOO=bar (nu --testbin echo_env_stderr FOO) e>| str length`

Which is hard to understand and hard to explain to users.

# User-Facing Changes
Nan

# Tests + Formatting
To be done

# After Submitting
Maybe update documentation about these syntax.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-triage An issue that hasn't had any proper look redirection-pipe All related to redirection to files or more complex pipelines with STDERR
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants