Some programs print their binary output directly on stdout. Here are some examples:

tar -c file.png
dd  if=file.png

Well, I see that the output can be redirected to a file. But these programs already accept output filenames as arguments. So, following commands will give the same results:

tar -c file.png  > file.tar
tar -c file.png -f file.tar

dd if=file.png  > copy.png
dd if=file.png of=copy.png

For what other purpose can binary output from stdout be used?

link|improve this question
From a program's point of view, stdout is just a file descriptor which you can write() to. What is the use of not allowing binary output to it? – grawity Sep 13 '11 at 11:07
feedback

2 Answers

up vote 7 down vote accepted

For building pipelines, obviously. The biggest advantage is that you can avoid having to create temporary files:

(For this example, assume an old version of tar which does not have -J or -I compression options.)

tar -c foo/*.png | xz -9 | uuencode "foo.tar.xz" | mail -s "Sending foo" musa
  • Now imagine if you had to use -f and stuff... you'd have VMS.

    tar -cf foo.tar foo/*.png
    xz -9 -o foo.tar.xz foo.tar
    uuencode -o foo.uue foo.tar.xz 
    mail -a foo.uue -s "Sending foo" musa
    rm foo.tar foo.tar.xz foo.uue
    

You can do pipelines over the network:

ssh storageserver "cd ~/foo && tar -c bar" | pv | tar -x

curl https://example.com/secret.gpg | ssh mylaptop "gpg --decrypt" > secret.zip

More examples:

curl http://i.imgur.com/L1aOt.jpg | display

And sometimes you don't even need to pipe it anywhere, even if the output is "binary". Try this on a Xterm:

curl http://www.dim13.org/tek/teapot.tek         # Utah teapot
link|improve this answer
feedback

Purposes may vary as per user. A developer can use that info for logging, or progress track or even error handling.

link|improve this answer
How do you log binary data, track progress or handle errors? Can you explain a bit? – slhck Sep 13 '11 at 8:41
@slhck: pv – grawity Sep 13 '11 at 9:07
1  
@grawity I know pv, but it would be nice for Mr. K to add a little more info. – slhck Sep 13 '11 at 9:19
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.