1

I'm using Amazon Linux and writing a script in bash. I want to output both stderr / stdout (preferably in the order that they occur) to a file as well as the console. However, this command isn't working ...

node test.js 2>&1 >> /tmp/output | tee --append /tmp/output

The output gets sent to the file, but it is not getting output to the console as it is happening. How can I correct the above to view the output?

1
  • The redirection to file should be at the end of the pipeline - then you can use tees to get output to terminal-screen and/or write/append to files before the final redirection. If you had a long pipeline with many commands, you would use redirection (>) to save the final result to a file. But you could use tees to also save several of the intermediate results to files... and/or to print one of the intermediate - or the final result - to the terminal-screen. Apr 28, 2016 at 19:25

1 Answer 1

3

The >> /tmp/output already sends all output to the file, leaving nothing to be sent to tee. So the command should read node test.js 2>&1 | tee --append /tmp/output.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .