(With many
screenfuls of text, such as test results for a set of test cases,
it'd be tedious and time consuming to screen capture.) (To get test results for a set of test cases, you'd usually use input/output redirection, i.e., do screen capture only as last resort.) |
The Linux's script facility can be used to capture (record) interactive screen displays as text. |
It is a very basic tool for capturing the screen displays of (a portion of) a user's interactive session (such as testing a program) under the Linux command-line environment. |
Being a very basic tool, script copies everything (including end-of-line markers, separators, etc. that often show up as funky characters in text) that is typed in by the user (and echoed on the screen) or written to the screen by the system or a program. |
|
|
|
|
|
|
|
|
|
|
Features/usage summary: |
![]() |
The user activates the facility at the point where (s)he wants capturing to start. |
![]() |
Typically, the user would do so by entering |
script filename |
where filename is the name of the text file that the user wants the captured output stored. |
![]() |
If the user does not provide a file name (i.e., enters only script), the default file name typescript will be used. |
![]() |
The facility will signal that it is activated by displaying |
Script started, output file is filename |
where filename is the file name that the user provides or typescript if the user chooses to use the default file name. |
![]() |
The user deactivates the facility at the point where (s)he wants capturing to end. |
![]() |
The user can do so either by entering |
exit |
or typing |
Ctrl-D |
(pressing the D key while holding down the Ctrl key). |
![]() |
The facility will signal that it is deactivated by displaying |
Script done, output file is filename |
where filename is the file name that the user provides or typescript if the user chooses to use the default file name. |
![]() |
Everything that has been displayed to screen between the activation point and the deactivation point will be captured to a text file named filename (if the user provides a custom file name) or typescript (if the user chooses to use the default file name). |
|
|
|
|
|
|
|
|
|
|
Example: |
![]() |
Capturing (to a file named capture1.txt) a session that lists the files in the current directory, compiles the hello.cpp program, lists the files again, and runs the compiled program: |
|
![]() |
Contents of capture1.txt (as seen in the vim editor): |
|
|
|
|
|
|
|
|
|
|
|
Shortcomings and how to make the best of it: |
![]() |
As can be seen from the example above, script captures everything that is displayed on the screen, including separators and end-of-line markers that translate into funky characters (highlighted in red in the example) in text. |
![]() |
Most (if not all) of the funky characters can be filtered out using the command |
sed -r 's/\^(\[){0,2}[0-9]{0,2}(;[0-9]{0,2})?[m|M]//g' rawFilename | col -b > filteredFilename |
where rawFilename is the name of the file with unfiltered contents and filteredFilename is the name of the file to store the filtered version. |
For instance, to filter the raw contents of capture1.txt above and store the filtered version in another file named cap1.txt, the command to use is as follows: |
sed -r 's/\^(\[){0,2}[0-9]{0,2}(;[0-9]{0,2})?[m|M]//g' capture1.txt | col -b > cap1.txt |
The following shows the contents of cap1.txt (as seen in the vim editor): |
|