This question already has an answer here:

doing this in bash script ./Execute_program > MyOutput I get a log file from the output, however this causes the output not to be displayed on the terminal screen. Is there any way to do the same but at the same time the output can be displayed on the screen?

marked as duplicate by Scott, mdpc, Michael Homer, Mongrel, Satō Katsura Feb 7 '17 at 4:43

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    program | tee myoutput – thrig Feb 6 '17 at 23:12

Use the universal pipe fitting, tee. tee reads input, and duplicates the output to both standard output and the specified file:

./Execute_program | tee MyOutput

If you want to append to rather than overwrite the specified file, use -a:

./Execute_program | tee -a MyOutput

If you want to write to several files, just add them as additional parameters:

./Execute_program | tee MyOutput MyOtherSavedLog

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