使选项以抑制输出

huangapple go评论63阅读模式
英文:

make option to suppress output

问题

我在Debian 12上编写一个Makefile来简化一些任务:

todo:
	su - user -c "/mypath/dothis"

现在,如果使用以下命令运行任务,我可以看到标准输出:

make todo

我在man make中查找了**-s silent**,但这只会隐藏命令,是否有一种方式可以抑制输出,或者这是唯一的方式:

make todo >> /dev/null 2>&1
英文:

I'm on Debian 12 writing a Makefile to simplify some tasks:

todo:
	su - user -c "/mypath/dothis" 

Now I can see the standard output from that task if run with:

make todo

I've checked in man make and found -s silent: but this hide only the command, is there a way suppress output or this is the only way:

make todo >> /dev/null 2>&1

答案1

得分: 1

以下是翻译好的部分:

使用简单的方法是将配方输出到 /dev/null

todo_quiet:
   @su - user -c "/mypath/dothis" > /dev/null 2>&1

然后运行 make todo_quite

您还可以使用命令行参数来实现:

Q := $(if $(V),,@)
Q_SUFFIX := $(if $(V),,> /dev/null 2>&1)

.PHONY: todo

todo:
   $(Q)su - user -c "/mypath/dothis" $(Q_SUFFIX)

您可以运行 make todo 以静默编译,运行 make todo V=1 以显示详细信息。如果要抑制任何 make 配方的所有输出,您将不得不将 make 的输出重定向到 /dev/null...

英文:

The simple way would be to make the recipe output to /dev/null:

todo_quiet:
   @su - user -c "/mypath/dothis" > /dev/null 2>&1

and then run make todo_quite

You could also do a command line parameter as so:

Q := $(if $(V),,@)
Q_SUFFIX := $(if $(V),,> /dev/null 2>&1)

.PHONY: todo

todo:
   $(Q)su - user -c "/mypath/dothis" $(Q_SUFFIX)

Where you would run make todo to compile quietly, and make todo V=1 to do it verbosely. If you want to suppress all output from any make recipe, you would have to pipe make's output to /dev/null...

huangapple
  • 本文由 发表于 2023年7月20日 22:07:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/76730737.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定