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

Redirect stderr #8277

Closed
MangoIV opened this issue Mar 1, 2023 · 2 comments · Fixed by #11708
Closed

Redirect stderr #8277

MangoIV opened this issue Mar 1, 2023 · 2 comments · Fixed by #11708
Labels
enhancement New feature or request redirection-pipe All related to redirection to files or more complex pipelines with STDERR
Milestone

Comments

@MangoIV
Copy link
Contributor

MangoIV commented Mar 1, 2023

Related problem

At the moment it is not possible to redirect stderr with a pipe, similar to bash's |&

Describe the solution you'd like

I would like to be able to have something like |& in nushell, perhaps we can even use the same thing as bash does to make it intuitive.

Describe alternatives you've considered

There are no real alternatives besides using a different shell

Additional context and details

The Bash reference manual, see chapter 3.2.3 - Pipelines

@fdncred
Copy link
Collaborator

fdncred commented Mar 28, 2023

@MangoIV in case you haven't seen this I'm posting it here for you #8539 (comment)

@MangoIV
Copy link
Contributor Author

MangoIV commented Mar 28, 2023

Thank you, I will try to look into it later.

WindSoilder added a commit that referenced this issue Feb 8, 2024
# Description
Close: #9673
Close: #8277
Close: #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 #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 #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.
@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
enhancement New feature or request 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