有没有办法告诉 GHC 将所有警告转储到文件中?

Is there a way to tell GHC to dump all warnings to a file?

到目前为止我已经尝试了以下方法:

me@pc:~/code$ ghc file.hs -Wall | tee warnings.log
me@pc:~/code$ ghc file.hs -Wall > warnings.log

但是ghc只是像正常情况一样打印警告并且只传递非警告步骤。

有办法吗?

它仍然显示这些警告的原因是因为警告和错误打印在标准 error 通道 (stderr) 上。

因此,您可以通过重定向 stderr 将错误重定向到文件,使用:

ghc file.hs -Wall <b>2></b> warnings.log

注意 <b>2</b>> 中的 2。如前所述,warningsexceptions 都打印到此频道。

我们可以将错误流重定向到 bash 中的 tee,方法是:

ghc -Wall file.hs <b>2> >(tee warnings.log)</b>

此功能适用于 bash,但据我所知,POSIX 标准中并未定义此功能。对于 bash 这有效,但对于 sh,这似乎失败了。