Friday, January 1, 2010

Redirect output and errors to null device

We often write scripts to automate tasks for us, however sometimes we don't want the output from individual programs to clutter the console output. In order to stop programs to output their console output, you can redirect them to the null device as below:

./example.pl > /dev/null 2>&1

This (1) redirects the output of example.pl to the null device and the (2) 2>&1 ensures that the output of the example.pl sends to the standard error (file descriptor 2), to wherever standard output (file descriptor 1) is going, which is, as already established, to the bitbucket.



No comments: