我试图抑制错误rm
通过书写命令
生成文件:
...
clean: $(wildcard *.mod)
-rm $^ 2>/dev/null
...
I ran:
$ make clean
rm 2>/dev/null
make: [clean] Error 64 (ignored)
我仍然收到错误。
无论如何,当我尝试时
$ rm [some non-existent files] 2>/dev/null
在 bash shell 上,它工作得很好。
我该如何使用2>/dev/null
在 makefile 中?
2>dev/null
将重定向错误输出,这样您就看不到它,它不会阻止 shell 提高错误级别。还有-
在你的 shell 命令前面签名会告诉你GNU make
即使错误级别升高,也会继续,但也不会阻止 shell 升高错误级别。
您想要的是 shell 不提高错误级别,可以这样做:
Unix(归功于这个答案 https://stackoverflow.com/a/14216161/6413048)
-rm $^ 2>/dev/null ; true
Windows
-rm $^ 2>NUL || true
或者如果你没有rm
在 Windows 上
-del /F /Q $^ 2>NUL || true
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)