寻找在Tcsh shell中将标准错误和标准输出重定向到日志文件的方法。
尝试了`./ShellFile.sh 2>&1 | pathToLogFile.log`,但出现了“模棱两可的输出重定向”错误。
欢迎任何意见。
首先,它不会是:
./ShellFile.sh 2>&1 | pathToLogFile.log
因为这样会尝试将你的输出通过名为 pathToLogFile.log 的可执行文件传输,而不是将输出发送到那里。
你需要:
./ShellFile.sh >& pathToLogFile.log
该命令将标准输出和错误都重定向到文件中。
顺便说一下,如果您想在终端 和 文件中都看到输出,则 tee(1) 可能会很有用。
./script 2>&1 | tee logfile.txt
tcsh
中不起作用,但在bash
中起作用。 - Stuart来自http://blog.elevenseconds.com/resources/shell-redirecting.html:
(cmd > /dev/tty) >& file1
>>&
。 - paxdiablotcsh
或者RaspPi下的版本有些不足之处。在Linux的tcsh
下它可以正常工作。 - paxdiablo