[RndTbl] UNIX command transcript with canned input, echoed in output?

Gilbert E. Detillieux gedetil at cs.umanitoba.ca
Fri Nov 25 15:26:46 CST 2011


On 2011-11-25 14:55, Adam Thompson wrote:
> Seems like a strange thing to ask for - how would you discriminate between
> input and output, since they'd likely be interleaved?

Actually, the whole point is to have the echoed input interleaved with 
the output, i.e. inserted where it belongs in the sequence.

Since the Prolog interpreter issues a prompt, this would make it fairly 
easy to distinguish input from output in the transcript, without the 
need for highlighting.

> 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.

No, separate files don't help, since the input is already available in a 
file.  The idea is exactly to interleave it.  Buffering issues might be 
a problem too...  This is why the solution would likely involve the use 
of pseudo ttys.  (Bill's suggestion of using "expect" is probably close, 
but more involved than what I'd like.)

-- 
Gilbert E. Detillieux		E-mail: <gedetil at muug.mb.ca>
Manitoba UNIX User Group	Web:	http://www.muug.mb.ca/
PO Box 130 St-Boniface		Phone:  (204)474-8161
Winnipeg MB CANADA  R2H 3B4	Fax:    (204)474-7609


More information about the Roundtable mailing list