I wish I could make script work like this:

❯ script --user=call.log --prog=response.log
    Script started

❯ echo foo

❯ exit
    Script done

❯ cat call.log
    echo foo

❯ cat response.log

Since it doesn't, I'm looking for alternatives.

Viewing the actual output of script shows something like this:

^M^[[35m❯ ^[[Ke^Hecho foo#[[?1l^[>^?2004l^M^M
^[]0;tmp: echo foo^Gfoo^M

I've considered writing a parser to pull what I want out of there--but that seems fragile, especially because it appears to depend on the user's shell configuration.

Is there a better way to log the ins and outs of a session separately?


Without knowing the internals of the various applications, you can't tell which characters were echoed by the terminal driver (on behalf of an application) and which were output by a given application.

I use script to capture the output for command-line applications like your example, and then use a script to filter out the escape sequences (see for example Can I programmatically “burn in” ANSI control codes to a file using unix utils?).

That wouldn't work as well for full-screen applications such as an editor (because it cannot show clearly what happens when the cursor moves around the screen, updating text). For that, it's (usually) good enough to replay the session in slow motion (e.g., slowcat).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.