编译程序并仅在编译失败时报告(不显示错误)
问题描述:
$2
具有C文件的路径。 问题是,当我编译有错误的文件时,它显示错误。我不想显示错误,我只是想说:“$ 2不能编译”。有任何想法吗?编译程序并仅在编译失败时报告(不显示错误)
cc $2
if test ! $? = 0
then
echo "$2 doesn't compile."
exit 1 # exit failure
fi
答
您可以通过它重定向到/dev/null
抑制cc
的输出:
if ! cc "$2" >/dev/null 2>&1 ; then
echo "$2 doesn't compile."
exit 1 # exit failure
fi
谢谢。我会更多地考虑这一点。 –