簡體   English   中英

使用Tee將管道輸入到兩個過程替代

[英]Pipe input to two process substitutions using tee

是否可以將輸入傳遞給兩個流程替換? 可以用tee完成嗎? 尚未找到解決方案。

我有一個我想使用流程替換運行的命令,如下所示:

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

我試圖將輸入通過管道傳遞給command2和command3,但我發現您無法兩次從管道讀取。

如果可能的話,使用tee的正確語法是什么?

也許您減少了太多示例,但是您可以這樣做:

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同時處理數據時才有效。 因此,在這種情況下,如果“命令”在從<input1讀取任何數據之前決定需要<(command2 <input2)所有數據,它將永遠等待,因為僅在命令command2請求時才發送一行,和命令3。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM