I am trying to log output from an interactive command-line program;
I have tried using
tee like this:
units | tee units.log
or script like this:
script -c units units.log
but they both log all the backspaces and tab completions as special characters like this:
You have: 55 horsepower ^G/^H^[[K^M You want: wat^Gt ^M * 41013.493^M / 2.438222e-05^M
The manpage for
script mentions this issue.
Script places everything in the log file, including linefeeds and backspaces. This is not what the naive user expects.
I am aware of the work-around with viewing the file using
more or stripping the escape characters with
col as mentioned here:
As well as the perl script here:
But I don't especially want to fix an existing log file: I want to avoid creating new log files garbled with deleted input and control characters.
I thought I had fixed the problem using
rlwrap, but it conflicts with the
units readline functionality, so that it either fails to capture the output, or with
rlwrap -a it captures the output but negates the ability of
units to use tab-completion.
rlwrap -a -N does not help. This is well-documented in the man page:
BUGS and LIMITATIONS
Though it is flexible, delivers the goods (readline functionality), and adheres to the Unix "many small tools" paradigm, rlwrap is a kludge. It cannot know anything about command's internal state, which makes context-sensitive completion impossible. Using the readline library from within command is still the best option.
Is there any way to cleanly log interactive input and output that doesn't mess with the existing
Update: I would be happy with something like
units | col -b | tee units.log
but that hangs while waiting for interactive input. Can this be fixed?