Millemila
Millemila

Reputation: 1660

Redirecting standard error to file and leaving standard output to screen when launching makefile

I am aware that for redirecting standard error and output to file I have to do:

make > & ! output.txt

Note I use ! to overwrite the file. But How can I redirect standard error to file and leave standard output to screen? Or even better having both error and output on file but also output on screen, so I can see how my compiling is progressing? I tried:

make 2>! output.txt 

but it gives me an error.

Upvotes: 1

Views: 2966

Answers (3)

Mark Armstrong
Mark Armstrong

Reputation: 440

You can do this simply with pipe into tee command. The following will put both stdout and stderr into a file and also to the terminal:

make |& tee output.txt

Edit

Explanation from GNU Bash manual, section 3.2.2 Pipelines:

If ‘|&’ is used, command1’s standard error, in addition to its standard output, is connected to command2’s standard input through the pipe; it is shorthand for 2>&1 |. This implicit redirection of the standard error to the standard output is performed after any redirections specified by the command.

Upvotes: 2

bmargulies
bmargulies

Reputation: 100051

You are reading bash/sh documentation and using tcsh. tcsh doesn't have any way to redirect just stderr. You might want to switch to one of the non-csh shells.

Upvotes: 1

hek2mgl
hek2mgl

Reputation: 158060

Note that > it enough to overwrite the file. You can use the tail -f command to see the output on screen if it is redirected to a file:

$(make 1>output.txt 2>error.txt &) && tail -f output.txt error.txt

Upvotes: 2

Related Questions