使用tee将输入管道输入到两个过程替换

问题描述 投票:1回答:1

是否可以将输入输入到两个过程替换?它可以用发球台完成吗?没有设法找到解决方案。

我有一个命令,我想使用这样的进程替换运行:

cat input.txt | command arg1 arg2 <(command2 </dev/stdin) arg3 <(command3 </dev/stdin) arg4

我试图通过管道传递输入到command2和command3但我发现你无法从管道读取两次。

如果可能的话,用tee做正确的语法是什么?

linux command-line pipe tee process-substitution
1个回答
0
投票

也许你已经减少了你的榜样,但你可以这样做:

cat input.txt | command arg1 arg2 <(command2 input.txt) arg3 <(command3 input.txt) arg4

或者没有猫。

<input.txt command arg1 arg2 <(command2 input.txt) arg3 <(command3 input.txt) arg4

但也许在管道之前有一个非常复杂的命令。不过,为什么不首先在文件中保护它并执行上述操作?

不过,也许输出非常大,你不想把它写到文件系统。然后,您可以使用命名管道,但有一个问题。

mkfifo input{1..3} # makes input1, input2, input3 as named pipes (!! named are still part of the file system !!)
complexcommand | tee input{1..3} & # tee will hang till it can send its output, therefor move it to the background with &
<input1 command arg1 arg2 <(command2 <input2) arg3 <(command3 <input3) arg4
rm -f input{1..3} # Since named pipes are part of the filesystem, better cleanup.

问题:以上可能会或可能不会起作用,具体取决于命令的行为。它仅在command,command2和command3同时处理数据时有效。因此,在这种情况下,如果“命令”在从<(command2 <input2)读取任何数据之前决定它需要来自<input1的所有数据,它将永远等待,因为只有在命令,command2和command3请求时才发送一行。

© www.soinside.com 2019 - 2024. All rights reserved.