Use the tee command:
$| tee [OUTPUT.FILE][COMMAND]
Where:
[COMMAND] is the command you want to execute.
[OUTPUT.FILE] is the file you want to write in.
Variation for writing the standard error output:
$2>&1 | tee[COMMAND][OUTPUT.FILE]
Where:
[COMMAND] is the command you want to execute.
[OUTPUT.FILE] is the file you want to write in.
2>&1 redirects stderr(2) to stdout(1).
Notes:
is different that2>&1.2>1
2>1 means writing to a file with name 1 and 2>&1 means write to the standard output.