1

This sequence of commands works OK:

pngtopnm file.png 2> /dev/null > dump1
pnmfile < dump1
stdin:  PPM raw, 1920 by 1080  maxval 255
ls -l dump1
-rw-r----- 1 cmb 6220817 Sep 15 14:26 dump1

But redoing the pipeline to use 'tee' truncates the output in the dump file:

pngtopnm file.png 2> /dev/null | tee dump2 | pnmfile
stdin:  PPM raw, 1920 by 1080  maxval 255
ls -l dump2
-rw-r----- 1 cmb   49152 Sep 15 14:34 dump2

I'm not clear on what difference it makes where 'tee' is sending stdin to what gets saved in the dump file - why is 'dump2' truncated, and not identical to 'dump1'?

cmp dump[12]
cmp: EOF on dump2 after byte 49152, in line 4

I suspect its something to do with 'pnmfile', since putting something else at the end of the pipeline seems to work OK - 'dump3' is the right size/same content as dump1, and the end of the pipe ('fmt') is doing something to the file...:

pngtopnm file.png 2> /dev/null  | tee dump3 |fmt -10 > dump4
ls -l dump[34]
-rw-r----- 1 cmb 6220817 Sep 15 14:41 dump3
-rw-r----- 1 cmb 6224311 Sep 15 14:41 dump4

(XUbuntu 20.04, diffutils 3.7, Netpbm 10.0, coreutils 8.30)

ColinB
  • 113
  • 3

1 Answers1

1
pngtopnm file.png 2> /dev/null | tee dump2 | pnmfile

pnmfile only reads until it has enough information to output the file information and then closes the pipe. At that point tee closes the pipe and dump2 as well.

Try tee -p dump2.

laktak
  • 5,616
  • 20
  • 38