1

I am using the tee command to output the compilation errors of a program into a file along with the terminal.

gcc hello.c | tee file.txt 

This is the command I have used. The compilation errors are displayed on the terminal but they are not outputted in the file. How should I output the std errors into file?

2
  • OK, good. Any question ? Commented Jan 7, 2015 at 9:53
  • tee only redirects stdout, compilation errors are presumably being output to stderr. See this post for more info on redirecting stderr with tee Commented Jan 7, 2015 at 9:59

1 Answer 1

5

With csh, tcsh, zsh or recent versions of bash, try

gcc hello.c |& tee file.txt

where

  • |& instruct the shell to redirect standard error to standard output.

In other Bourne-like shells:

gcc hello.c 2>&1 | tee file.txt

In rc-like shells:

gcc hello.c >[2=1] | tee file.txt

In the fish shell:

gcc hello.c ^&1 | tee file.txt
2
  • This is a bash 4 feature. For older versions of bash, use 2>&1 | instead. Commented Jan 7, 2015 at 10:07
  • @AnsgarEsztermann, that's a (t)csh feature, also available in zsh and recently added to bash. Commented Jan 7, 2015 at 10:09

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.