我将使用 Maven 的 Pitest (PIT) 应用到 Java 项目以进行突变分析。控制台的管道运算符仅捕获与 Maven 相关的输出,但不捕获 PIT 的输出。(这在 Linux 和 Windows 上都会发生。)
如何将控制台上显示的日志输出重定向到文件?
Maven 输出将转至stdout
某些 PIT 日志将转至stderr
. 您还需要重定向stderr
以获取所有日志。
# this will write both outputs to a file
mvn clean install &> both-outputs.log
# this will also write both outputs to a file
mvn clean install > both-outputs.log 2>&1
# to pipe both outputs you need to do this
mvn clean install 2>&1 | any-command-reading-from-stdin