2

I should compile and run my file and record it with script in a typescript. But when I try it I get unexpected results in the file. Am I doing something wrong?

$ script
Script started, file is typescript
developer@developer-VirtualBox:~/Desktop/kth/os/smallshell/oslab$ gcc -Wall -O4 -ansi -pedantic miniShell.c
developer@developer-VirtualBox:~/Desktop/kth/os/smallshell/oslab$ exit
exit
Script done, file is typescript
developer@developer-VirtualBox:~/Desktop/kth/os/smallshell/oslab$ more typescript 
Script started on Mon 18 May 2015 06:38:38 CEST
developer@de
-ansi -pedantic miniShell.cp/kth/os/smallshell/oslab$ gcc -Wall -O4  
developer@de
veloper-VirtualBox:~/Desktop/kth/os/smallshell/oslab$ exit
exit

Script done on Mon 18 May 2015 06:38:58 CEST
developer@developer-VirtualBox:~/Desktop/kth/os/smallshell/oslab$ 
1
  • 2
    Try looking at it in less or an editor that is smarter about control characters. script writes a very exacting rendition of the session and things that aren't expecting control characters will not display it correctly. Commented May 18, 2015 at 4:55

1 Answer 1

1

script records all characters sent to your terminal. That includes all kinds of terminal control sequences (such as cursor movement, colors, etc).

By default, less (and other pages) do not work well with these control characters. Use the -R option of less to allow the program to render the file as it was originally sent. There are some limitations, since even this presumes that the file is not generated in fullscreen mode. To handle that, your best choice is to slowly cat the file to a terminal with the same size as that on which the file was generated. For that, I use a program slowcat. Others use a -t option to script which records timing information (but that is not available on all versions of script — essentially, Linux-specific).

Alternatively, you can use a program or script to remove these control sequences, and get something comparable (without video highlights and colors) to that which less -R would show. Some discussion of how to do this is found in Can I programmatically “burn in” ANSI control codes to a file using unix utils?.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.