Chapter 3 of 14
Where did the output go?
Two operators want different things from the same report. One wants to see a single matching line. The other wants both a display and a saved copy. Neither should have to rewrite the program producing the text.
Connect paths zero, one and two
A path number is a small handle valid in the process using it. A newly started command ordinarily inherits three paths from its parent. At an interactive shell, more than one of these can reach the same terminal.
| Path | Conventional use | Change it in Shell+ |
|---|---|---|
| 0, standard input | Read a key or the next bytes of an input stream | < followed by an input filename |
| 1, standard output | Deliver the command’s regular result | > followed by a new output filename |
| 2, standard error | Deliver diagnostic messages, status and prompts | >> followed by a new diagnostic filename |
Shell+ arranges the destinations before starting the child. A program that writes to path 1 naturally follows the new destination. A program that opens /Term explicitly has made a different choice. In particular, >> on this shell selects path 2. Treating it as a request to append to an existing report can produce an error or put the wrong stream in a file.
Filter a listing, then split a stream
From /H1/station run these commands. Choose an unused name for archive if repeating the exercise.
list report ! grep beacon
echo radio ! tee archive
list archive
The exclamation mark joins one command’s output to another command’s input. In the first pipeline, List sends both lines of the procedure down a pipe. Grep emits the line containing echo beacon online. The pwd line fails the match. In the second pipeline, Tee reads the line produced by Echo, writes it to the file archive, and also sends it to its own standard output. You see radio twice, once during the pipeline and once when List reads the saved file.
A pipe is a stream between open paths. OS-9 can schedule the reader while the writer is producing more bytes. Once every writer closes its path and the reader consumes the remaining bytes, the reader reaches end of input. A disk file has a directory entry and remains available to a future process. You can come back to archive after a reboot.
Catch a diagnostic separately
Use build fail in your practice directory. Give it one line, list absent, and then an empty Return. Leave absent as a deliberately unused filename. At Shell+ type:
shell <fail >>errors
list errors
The child shell tries to list a missing file. Most of the usual terminal chatter disappears. Opening errors afterward reveals its prompts, ERROR #216, and eof. In our session a short Shell+ banner still appeared on the terminal. This tells you why a useful diagnostic capture includes path 2 even when some messages still reach path 1. The file errors needs a fresh name for a second run.
The earlier filter, file copy and diagnostic capture all pass text through the same three numbered paths. Remember path 1. The report writer you assemble at the end of the book uses that number directly.