Redirecting output
This page talks about redirecting output from a process (app) that you run using one of the DCLI commands such as 'start'.
If you are not familiar with concepts such as stdout and stdin then have a read of our primer on stdin/stdout/stderr.
If you have used bash then you may be familiar with the bash redirect operator '>'. DCli also allows you to redirect output and the most common method we use is a 'Progress'.
So let's have a look at how we use Progress to redirect the output of the 'start' command.
By default, the start
command prints all output (stdout and stderr) to the console. But what if we want to redirect stdout to a log file?
Passing a Progress to the 'start' command allows you to redirect both stdout and stderr independently.
redirect stdout to a log
Redirect stderr
Redirect stderr to a log whilst still printing to stdout to the console
long hand
The above two examples use tear-offs which make it a little hard to understand what is going on so let's do it the long way:
dealing with errors
When a console app writes to stderr it may also exit with a non-zero exit code.
By default, the DCli 'start' command will throw an exception if an app exits with any value but zero.
If you are looking to process the output from stderr in order to take some action when an error occurs, then you need to suppress DCli's default behaviour of throwing an exception.
In this case, you need to pass the 'nothrow' argument to start.
Last updated