Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^2: Wanted: humanly readable `script` output

by mrslopenk (Acolyte)
on May 04, 2008 at 20:11 UTC ( [id://684471]=note: print w/replies, xml ) Need Help??


in reply to Re: Wanted: humanly readable `script` output
in thread Wanted: humanly readable `script` output

Thanks for the suggestions everyone, but there are a lot of other control characters besides the backspace. If you are at a unix terminal, try this:
script ls exit
Then look in typescript. You'll see what I mean. Actually, there is a semi-passable solution that does not involve perl:
TERM=dumb script ls exit cat typescript | col -b > readable.txt
This seems to work as long as all the commands you type after script work on a dumb terminal. I was just wondering if perl had a more robust solution. I had a look at Term::Cap, but I fail to understand how to use it. I feel there must be a solution because, after all, I can see the very text I want on the terminal screen -- it's all right there! -- until my buffer size is reached. Usually copy/paste with the mouse from terminal to emacs works ok, but it didn't work the other night when I was compiling a kernel -- the output exceeded my buffer size.

Replies are listed 'Best First'.
Re^3: Wanted: humanly readable `script` output
by pc88mxer (Vicar) on May 04, 2008 at 20:33 UTC
    To capture the output of a kernel compile, why not just redirect the output?
    make zImage... > compile-output 2>&1
    Also, I usually put such commands in the background and tail the output file occasionally to see how things are going,
      Yes, that would have been a good idea. Still, I would like a transcript of both the commands I typed and the output.

      Moreover, it would make the perl-kiddie in me quite happy if I could parse terminal control codes in my favorite language.
Re^3: Wanted: humanly readable `script` output
by mrslopenk (Acolyte) on May 04, 2008 at 20:25 UTC
    #!/usr/bin/perl use strict; use warnings; open(FILE,"<","typescript") || die; while (my $line=<FILE>) { $line=~s/.\x08//g; $line=~s/\p{IsC}//g; print "$line\n"; } close(FILE);
    This left behind a lot of funny things, which, to my eyes look like:
    [00m, [01;34m, [01;35m, [m]0;
    characters.

      What is left looks like the colour control sequences for a fancy bash prompt. You might want to set the prompt to something humble with, say

      export PS1='\u@\h\$ '

      loris


      "It took Loris ten minutes to eat a satsuma . . . twenty minutes to get from one end of his branch to the other . . . and an hour to scratch his bottom. But Slow Loris didn't care. He had a secret . . ." (from "Slow Loris" by Alexis Deacon)
Re^3: Wanted: humanly readable `script` output
by ikegami (Patriarch) on May 05, 2008 at 06:40 UTC

    This seems to work as long as all the commands you type after script work on a dumb terminal. I was just wondering if perl had a more robust solution

    How could removing terminal-specific control sequences be any more robust than not having them in the first place?

    The next best solution would be to have some program which process's your terminal's control sequences to generated a flat file. However, emulating a devices is rather complex and error-prone (hardly robust), and you'll have to make some concession or another in order to handle text being overwritten.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://684471]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2024-04-24 18:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found