pass stdout as file name for command line util?

前端 未结 5 2089
醉酒成梦
醉酒成梦 2020-11-30 03:23

I\'m working with a command line utility that requires passing the name of a file to write output to, e.g.

foo -o output.txt

The only thing

5条回答
  •  鱼传尺愫
    2020-11-30 03:47

    Named pipes work fine, but you have a nicer, more direct syntax available via bash process substitution that has the added benefit of not using a permanent named pipe that must later be deleted (process substitution uses temporary named pipes behind the scenes):

    foo -o >(other command)

    Also, should you want to pipe the output to your command and also save the output to a file, you can do this:

    foo -o >(tee output.txt) | other command

提交回复
热议问题