start page | rating of books | rating of authors | reviews | copyrights

UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 13.4 Problems Piping to a Pager Chapter 13
Redirecting Input and Output
Next: 13.6 Safe I/O Redirection with noclobber
 

13.5 Redirection in C Shell: Capture Errors, Too?

The > (right angle bracket) operator redirects the standard output of a process to a file. It doesn't affect the standard error. If you're logged in and can see any messages written to standard error, that's okay:

% 

nroff -ms report.ms > report.out &

 [1] 10316    ...
Later
... nroff: can't open file /hoem/jpeek/report.data

But if you log out and leave the job running, you'll never see those errors unless you use the csh operator >& . It redirects both standard output and standard error to a file. For example:

 
make
          
 % 

make >& make.output &

 [1] 10329 % 

logout

    ...
Later
... % 

cat make.output

         cc -O -c random.c         cc -O -c output.c "output.c", line 46: syntax error "output.c", line 50: time_e undefined "output.c", line 50: syntax error    ...

You might also use the >& operator while you're logged in - and watch the output file with tail -f ( 25.16 ) . If you don't want the errors mixed with other output, you can split them to two files; see article 13.1 .

The C shell also has a pipe operator, |& , that redirects both standard output and standard error. It's great for running a job in the background, or on another computer, and mailing ( 1.33 ) any output to me:

% 

make |& mailx -s "'make bigprog' output" [email protected] &

 [1] 29182 29183

If I'd used plain | instead of |& , any text on the standard error wouldn't go into the mail message.

- JP


Previous: 13.4 Problems Piping to a Pager UNIX Power Tools Next: 13.6 Safe I/O Redirection with noclobber
13.4 Problems Piping to a Pager Book Index 13.6 Safe I/O Redirection with noclobber

The UNIX CD Bookshelf Navigation The UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System