mercredi 28 janvier 2015

tar to pipe but keep verbose STDOUT separate


A normal tar command



tar cvf foo.tar ./foo >foo.out 2>foo.err


has three output IO streams



  • archive data to foo.tar

  • list of filenames to STDOUT (redirected into foo.out)

  • error messages to STDERR (redirected into foo.err)


I can then inspect foo.err for error messages without having to read through the list of filenames.


if I want to do something with the archive data (pipe it through netcat or a special compression program) I can use tar's -f - option thus



tar cvf - ./foo 2>foo.err | squish > foo.tar.S


But now my list of filenames is mixed in with my error messages because tar's -v output obviously can't go to STDOUT (that's where the archive data flows) so tar cleverly writes that to STDERR instead.


Using Korn shell, is there a way to construct a command that pipes the archive stream to another command but still capture the -v output separately from any error messages.



Aucun commentaire:

Enregistrer un commentaire