The send_error Command
A task related to printing information is that of printing error messages. It is a good idea to print error messages in such a way that they can be easily separated from the normal output of the program. In particular, error messages go to the standard error stream while normal output goes to the standard output stream.
The benefit of sending errors to a separate stream is that, once separated, the two streams can be easily sent to different places. Typically, the standard output is redirected to a file or piped to another process while the standard error remains undirected so that it can be seen at the terminal.[33] For example, the command "cat foo | wc
" (to count the words in foo
) will print "foo: no such file
" if foo
does not exist. You see the error message because the standard error is not redirected. If the diagnostic was sent along with the normal output of cat
, wc
would report that foo
had four words only because that is how many are in the error message!
Expect scripts should be written the same way. Normal output that you might wish to redirect or pipe should be sent to the standard output. Error messages should be sent to the standard error. There are two ways of doing this: send_error
and "puts stderr
“. send_error
is similar to send_user
and send
whereas "puts stderr
" is similar to puts
.
I will show more differences later. To summarize the differences so far between variations on puts
and the variations on send
:
| automatically appends newline ... |
Get Exploring Expect now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.