Home Explore Blog CI



nushell

3rd chunk of `lang-guide/chapters/pipelines.md`
1082ad098798c96de4431adc9d3ac6cfa01c01a9796b5bb90000000100000d5d
| cmd3    | Piped    | Terminal |
| cmd4    | Terminal | Piped    |

- (^cmd1 | ^cmd2; ^cmd3 | ^cmd4) o+e>| ^cmd5

It runs `(^cmd1 | ^cmd2; ^cmd3 | ^cmd4)` first, then pipes _stdout and stderr_ to `^cmd5`, where both stdout and stderr are directed to the Terminal.

| Command | Stdout   | Stderr   |
| ------- | -------- | -------- |
| cmd1    | Piped    | Terminal |
| cmd2    | Terminal | Terminal |
| cmd3    | Piped    | Terminal |
| cmd4    | Piped    | Piped    |

- (^cmd1 | ^cmd2; ^cmd3 | ^cmd4) o> test.out

| Command | Stdout | Stderr   |
| ------- | ------ | -------- |
| cmd1    | Piped  | Terminal |
| cmd2    | File   | Terminal |
| cmd3    | Piped  | Terminal |
| cmd4    | File   | Terminal |

- (^cmd1 | ^cmd2; ^cmd3 | ^cmd4) e> test.out

| Command | Stdout   | Stderr |
| ------- | -------- | ------ |
| cmd1    | Piped    | File   |
| cmd2    | Terminal | File   |
| cmd3    | Piped    | File   |
| cmd4    | Terminal | File   |

- (^cmd1 | ^cmd2; ^cmd3 | ^cmd4) o+e> test.out

| Command | Stdout | Stderr |
| ------- | ------ | ------ |
| cmd1    | Piped  | File   |
| cmd2    | File   | File   |
| cmd3    | Piped  | File   |
| cmd4    | File   | File   |

### Examples for custom command

Given the following custom commands

```nu
def custom-cmd [] {
    ^cmd1 | ^cmd2
    ^cmd3 | ^cmd4
}
```

The custom command stdio behavior is the same as the previous section.

In the examples below the body of `custom-cmd` is `(^cmd1 | ^cmd2; ^cmd3 | ^cmd4)`.

- custom-cmd

| Command | Stdout     | Stderr   |
| ------- | ---------- | -------- |
| cmd1    | Piped      | Terminal |
| cmd2    | _Terminal_ | Terminal |
| cmd3    | Piped      | Terminal |
| cmd4    | Terminal   | Terminal |

- custom-cmd | ^cmd5

It runs `custom-cmd` first, then pipes _stdout_ to `^cmd5`, where both stdout and stderr are directed to the Terminal.

| Command | Stdout     | Stderr   |
| ------- | ---------- | -------- |
| cmd1    | Piped      | Terminal |
| cmd2    | _Terminal_ | Terminal |
| cmd3    | Piped      | Terminal |
| cmd4    | Piped      | Terminal |

- custom-cmd e>| ^cmd5

It runs `custom-cmd` first, then pipes _stderr_ to `^cmd5`, where both stdout and stderr are directed to the Terminal.

| Command | Stdout   | Stderr   |
| ------- | -------- | -------- |
| cmd1    | Piped    | Terminal |
| cmd2    | Terminal | Terminal |
| cmd3    | Piped    | Terminal |
| cmd4    | Terminal | Piped    |

- custom-cmd o+e>| ^cmd5

It runs `custom-cmd` first, then pipes _stdout and stderr_ to `^cmd5`, where both stdout and stderr are directed to the Terminal.

| Command | Stdout   | Stderr   |
| ------- | -------- | -------- |
| cmd1    | Piped    | Terminal |
| cmd2    | Terminal | Terminal |
| cmd3    | Piped    | Terminal |
| cmd4    | Piped    | Piped    |

- custom-cmd o> test.out

| Command | Stdout | Stderr   |
| ------- | ------ | -------- |
| cmd1    | Piped  | Terminal |
| cmd2    | File   | Terminal |
| cmd3    | Piped  | Terminal |
| cmd4    | File   | Terminal |

- custom-cmd e> test.out

| Command | Stdout   | Stderr |
| ------- | -------- | ------ |
| cmd1    | Piped    | File   |
| cmd2    | Terminal | File   |
| cmd3    | Piped    | File   |
| cmd4    | Terminal | File   |

- custom-cmd o+e> test.out

| Command | Stdout | Stderr |
| ------- | ------ | ------ |
| cmd1    | Piped  | File   |
| cmd2    | File   | File   |
| cmd3    | Piped  | File   |
| cmd4    | File   | File   |

Title: Standard I/O and Redirection Behavior with Custom Commands
Summary
This section continues the discussion on standard input/output (stdio) and redirection behavior, now focusing on custom commands defined in Nushell. It uses a `custom-cmd` example consisting of a sequence of piped commands and shows how stdout and stderr are handled when the custom command is used in pipelines or with redirections to files or other commands. Tables illustrate the output and error stream destinations for each command within the custom command under various redirection scenarios.