Redirect output from command to terminal and a file without using tee

Viewed 34

As the name implies, I want to log the output of a command to a file without changing the terminal behavior. I still want to see the output and importantly, I still need to be able to do input.

The input requirement is why I specifically cannot use tee. The application I am working with doesn't handle input properly when using tee. (No, I cannot modify the application to fix this). I'm hoping a more fundamental approach with '>' redirection gets around this issue.

Theoretically, this should work exactly as I want, but, like I said, it does not.

command | tee -a foo.log

Also notice I added the -a flag. Not strictly required because I can definitely do a work around but it'd be nice if that was a feature as well.

1 Answers

Use script.

% script -c vi vi.log
Script started, output log file is 'vi.log'.
... inside vi command - fully interactive - save the file, takes to:
Script done.
% ls -l vi.log
-rw-r--r-- 1 risner risner 889 Sep 13 15:16 vi.log
Related