-----Original Message----- From: roundtable-bounces@muug.mb.ca [mailto:roundtable- bounces@muug.mb.ca] On Behalf Of Gilbert E. Detillieux Sent: Friday, November 25, 2011 1:57 PM To: MUUG Roundtable Subject: [RndTbl] UNIX command transcript with canned input, echoed in output?
Howdy folks!
I got a request from a prof this morning that stumped this old UNIX hack. He wants to run a UNIX command (for a language interpreter), using input from a file, and saving a transcript of the output. That much is trivial. The catch is that he'd like the transcript to have the input echoed, as if it had been typed in at the tty.
I've looked at options on the script command and ssh, but can't find a simple solution to this. And it has to be simple enough for his students (who may not have much UNIX experience) to use.
Any suggestions?
Seems like a strange thing to ask for - how would you discriminate between input and output, since they'd likely be interleaved?
Anyway, the best I can suggest is:
tee copy-of-input < inputfile | interpreter 2>&1 | tee copy-of-output
which would leave you with two files. Of course, this could be wrapped in a trivial function like:
run_script() { DATE=$( date +%F_%T.%N ) cat ${1:-} | tee "input-${DATE}" | interpreter 2>&1 | tee "output-${DATE}" }
in order to make it more easily accessible for novices. Obviously this wouldn't work terribly well for interactive use due to buffering issues; if there were a --line-buffered option for tee(1) this could be workable but no such option exists in GNU tee.
-Adam