Diff two pipes originating from the same source

I found the answer how to split two pipes in SO, and the syntax is shown below.

diff <(./a.out) <(./a.out | sort -n)

However, it will create two a.outproven processes ps. Is it possible to have only one a.out, translate the output into two streams and distinguish between these two streams?

./a.out | tee >(cat) >(sort -n)

I can broadcast using tee, but do not know how to use diff.

Any suggestion?

Edit: Why don't I want to create two processes? The reason is that this is one parallel program, so the output is not deterministic. Therefore, I have to use the same output from one process.

+4
source share
2 answers

, , 2 , , , fifo, :

mkfifo fifo
diff <(./a.out | tee fifo) <(sort < fifo)
+1

,

, . /a.out > file1

cat file1 | sort -n > file2

diff file1 file2

( ) rm file1 file2

a.out, diff

0

Source: https://habr.com/ru/post/1548211/


All Articles