开发者

Redirect Standard Output/error to log file

开发者 https://www.devze.com 2023-02-05 10:14 出处:网络
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

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 a开发者_高级运维nd got the error "Ambiguous output redirect"

Would appreciate any inputs.


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.


On a side note, tee(1) may be of use if you want to see output both on the terminal and in a file.

  ./script 2>&1 | tee logfile.txt


From http://blog.elevenseconds.com/resources/shell-redirecting.html :

(cmd > /dev/tty) >& file1
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号