Redirect Standard Output/error to log file

Piyush Mattoo picture Piyush Mattoo · Jan 18, 2011 · Viewed 38.4k times · Source

Looking for a way to redirect std error and std output to a log file in Tcsh shell.

Tried ./ShellFile.sh 2>&1 | pathToLogFile.log and got the error "Ambiguous output redirect"

Would appreciate any inputs.

Answer

paxdiablo picture paxdiablo · Jan 18, 2011

For a start, it wouldn't be:

./ShellFile.sh 2>&1 | pathToLogFile.log

since that would try and pipe your output through the executable file called pathToLogFile.log rather than sending the output there.

You need:

./ShellFile.sh >& pathToLogFile.log

which redirects both standard output and error to the file.