21

Redirection operator does not work. So how should we do it? One more question, in makefile, how can we give arguments from command line, like

run: a.out
    ./a.out **<input>**
avd
  • 13,993
  • 32
  • 78
  • 99

3 Answers3

29

gcc prints its error messages to stderr, so you have to redirect stderr:

gcc -o foo foo.c 2> foo.gccmessages

You give arguments on the command line always in the same way

./a.out argument1 argument2 argument3
Tharif
  • 13,794
  • 9
  • 55
  • 77
Martin v. Löwis
  • 124,830
  • 17
  • 198
  • 235
  • In makefile, I want to specify that input will be given from command line.I am not asking how to give input at command line? How to do that? – avd Sep 29 '09 at 05:52
  • 2
    You do that by asking a separate question and getting answers to it. – P Shved Sep 29 '09 at 05:55
  • Ok I got that, if we want to append the output to a existing file, then what should we do? – avd Sep 29 '09 at 05:59
6

Try: $ make 2>&1 | tee your_build_log.txt this will redirect stdout, 2>&1 redirects stderr to the same place as stdout while allowing you to simultaneously see the output in your terminal.

see: How do I capture all of my compiler's output to a file?

Community
  • 1
  • 1
rpappalax
  • 101
  • 1
  • 4
0

A detailed documentation for I/O redirection for stdout,stderr is given in this document(1).Peripheral devices like stdin(eg:keyboard), stdout(eg: computer monitor) and stderr(error messages from the output of a gcc compilation) are considered as files.