1755960 Members
4186 Online
108839 Solutions
New Discussion юеВ

Redirect standard error

 
SOLVED
Go to solution
A. Clay Stephenson
Acclaimed Contributor

Re: Redirect standard error

Well, Ryan, being mathematically limited is a personal problem but it's not too late to fix. In all seriousness, once the bunch of engineers that I once had to support saw that I could handle differential equations, it was duck soup. Of course, I told them it was alright to be engineers; at least they weren't chemists. Using "The Force" I sense that you are probably supporting a bunch of guys doing Finite Element Analysis; if so, I am very familiar with the vendor supplied C Shell scripts and they were ugly. You may also be doing CFD but I really sense FEA. In my case, the only reason the C shell was used was to increase soft data ulimit values which both the Korn and POSIX shells now do.

If it ain't broke, I can fix that.

Re: Redirect standard error

The following command saves stdout and stderr to the files "out.txt" and "err.txt", respectively.


[root@server /root]# ./cmd 1>out.txt 2>err.txt




The following command appends stdout and stderr to the files "out.txt" and "err.txt", respectively.


[root@server /root]# ./cmd 1>>out.txt 2>>err.txt




The following command functions similar to the above two commands, but also copies stdout and stderr to the files "stdout.txt" and "stderr.txt", respectively.


[root@server /root]# (((./cmd | tee stdout.txt) 3>&1 1>&2 2>&3\
|tee stderr.txt) 3>&1 1>&2 2>&3) 1>out.txt 2>err.txt


It Has Been...
A. Clay Stephenson
Acclaimed Contributor

Re: Redirect standard error

Note that this was a C shell question so the last solution proposed is a non sequitur --- although valid for other (and arguably better) shells.
If it ain't broke, I can fix that.
Mike Seidel
New Member

Re: Redirect standard error

Ryan,

Redirect stdout first, then redirect to stderr

(find / -name foo -print > ~/bar) &> ~/bat

would be equivalent to

find / -name foo -print 1> ~/bar 2> ~/bat

in bash/korn

not that

( find / -name gimp -print > foo ) > & /dev/null &;tail -f foo is as easy as 2>/dev/null, but...