script: I am missing "tee"

I know we can write a filter for it, but having tee in the set of filter would be nice.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 26 (20 by maintainers)

Most upvoted comments

os.OpenFile("/dev/null"...

If you just want a writer to nowhere, you can use io.Discard.

The append behaviour sounds more useful, doesn’t it? This sort of design problem is always a case of drawing a fine line between what’s useful, and what inflates the API more than it’s worth.

I forked script into my repsitory, I added a Tee function to it, and added a test for it in script_test.go.

script] $ go test -v | grep -i tee
=== RUN   TestTeeOutput
=== PAUSE TestTeeOutput
=== CONT  TestTeeOutput
--- PASS: TestTeeOutput (0.01s)

If Bitfield could review it I could issue a pull request – just want to make sure that’s ok with him before I do a pull request. https://github.com/rmasci/script

What if I don’t want the file truncated? What if I want the results put to my main log file? Or I want one file, for several different script.Exec().Tee()? Passing a writer gives the programmer the flexibility of how the file is open and the ability to error before the pipeline if the file can’t be open / written to.