Logging interactive input and output without capturing all typed input and control characters
5
votes
1
answer
1487
views
I am trying to log output from an interactive command-line program; [
units
](https://www.gnu.org/software/units/) , specifically.
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.
> **BUGS**
>
> 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 cat
and more
or stripping the escape characters with col
as mentioned here:
https://stackoverflow.com/questions/7152339/format-output-from-unix-script-command-remove-backspaces-linefeeds-and-delet
As well as the perl script here:
http://log.guidoderosa.net/2009/05/another-old-post-which-may-be-useful.html
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 readline
functionality?
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?
Asked by Nathaniel M. Beaver
(1398 rep)
Nov 15, 2013, 04:30 AM
Last activity: Feb 6, 2019, 05:42 PM
Last activity: Feb 6, 2019, 05:42 PM