File 编译程序并仅在编译失败时报告(不显示错误)
File 编译程序并仅在编译失败时报告(不显示错误),file,shell,compilation,File,Shell,Compilation,$2具有C文件的路径。 问题是,当我编译一个有错误的文件时,它会显示错误。我不想显示错误,我只想让它说:“$2不能编译。”有什么想法吗 cc $2 if test ! $? = 0 then echo "$2 doesn't compile." exit 1 # exit failure fi 您可以通过将cc的输出重定向到/dev/null来抑制它: if ! cc "$2" >/dev/null 2&
$2
具有C文件的路径。
问题是,当我编译一个有错误的文件时,它会显示错误。我不想显示错误,我只想让它说:“$2不能编译。”有什么想法吗
cc $2
if test ! $? = 0
then
echo "$2 doesn't compile."
exit 1 # exit failure
fi
您可以通过将
cc
的输出重定向到/dev/null
来抑制它:
if ! cc "$2" >/dev/null 2>&1 ; then
echo "$2 doesn't compile."
exit 1 # exit failure
fi
非常感谢。我会进一步调查的。