Results 1 to 5 of 5
Dear Linux experts:
On the terminal, usually one can use ">" to pipe output to a text file. However, sometimes, ">" does not work and output message still only go ...
- 01-04-2008 #1Just Joined!
- Join Date
- Nov 2006
- Posts
- 96
How to save screen output to a text file?
Dear Linux experts:
On the terminal, usually one can use ">" to pipe output to a text file. However, sometimes, ">" does not work and output message still only go to the screen. For example, if I try to compile a piece of program by typing "make", for example, "make > output.txt". This will not capture all the output message from the computer. Is there a way to capture EVERYTHING to a text file? Thanks!
phsieh2005
- 01-04-2008 #2Just Joined!
- Join Date
- Jan 2008
- Posts
- 2
Re: How to save screen output to a text file?
A normal "text mode" program has three files opened on launch:
- stdin (on FD=0) is standard input
- stdout (on FD=1) is standard output
- stderr (on FD=2) is standard error output
The method for redirecting stderr differs depending on which shell you are using, but always tends to involve the character "&":
- in csh: program <infile >&outfile
- in bash: program <infile 2>&1 >outfile
- 01-04-2008 #3Just Joined!
- Join Date
- Nov 2006
- Posts
- 96
Thanks!
Hi, lpoulsen:
Thanks for the reply!
I am using bash. Can I use: "make >> output.log 2>&1"? Or "make 2>&1 > output.log"? since make does not have input file.
phsieh2005
- 01-04-2008 #4
Check here
course:book:chap_05 [LBo]
- 07-09-2010 #5Just Joined!
- Join Date
- Mar 2010
- Location
- Pittsburgh
- Posts
- 3
output to file (bash)
2.5 years later, but "better late than never" and I was looking for clarification on this (i.e. so others still might be):
make 2> output.log # creates/overwrites output.log
make 2>> output.log # appends to output.log
lpoulsen was just putting all possibilities in one generic statement; i.e. if inputting from a file, place "< file" before the "2>" or "2>>" and/or if outputting to file, put " file" after the "2>" or "2>>".
Also, just FYI:
"make > output.log" and "make 1> output.log" would be the same
"make >> output.log" and "make 1>> output.log" would be the same
"make 2>&1> output.log" or "make 2>&1>> output.log" puts STDERR *and* STDOUT stuff in the output.log (and "2>>&1>>" doesn't work; i.e. whether to append or not depends on the final redirect symbol)
I stick to STDOUT *or* STDERR (as opposed to *and*) because, as one example, "tar -f tarfile file 2>&1> file.log" doesn't redirect the STDERR to the file (if there is any), but rather to the screen (but "tar -f tarfile file 2> file.log" works as expected).



