Stdout, Stderr, and Exit Codes
The first of these important streams is stdout.
Stdout is the way that most external apps will send data into the pipeline or to the screen. Data sent by an external app to its stdout is received by Nushell by default if it’s part of a pipeline:
The above would call the external named and would redirect the stdout output stream into the pipeline. With this redirection, Nushell can then pass the data to the next command in the pipeline, here .
Without the pipeline, Nushell will not do any redirection, allowing it to print directly to the screen.
You can force Nushell to do a redirection by using . For example, if we wanted to call the external above and redirect its stderr, we would write:
Finally, external commands have an “exit code”. These codes help give a hint to the caller whether the command ran successfully.
Nushell tracks the last exit code of the recently completed external in one of two ways. The first way is with the environment variable.
The second uses a command called complete.
If we try to run the external on a file that doesn’t exist, we can see what does with the streams, including the redirected stderr:
Both stdout and stderr are represented as “raw streams” inside of Nushell. These are streams that are streams of bytes rather than structured streams, which are what internal Nushell commands use.
Because streams of bytes can be difficult to work with, especially given how common it is to use output as it was text data, Nushell attempts to convert raw streams into text data. This allows other commands to pull on the output of external commands and receive strings they can further process.
Nushell attempts to convert to text using UTF-8. If at any time the conversion fails, the rest of the stream is assumed to always be bytes.