Creating scripts of test runs in UNIX

Introduction
There are many situations where it is useful to save a copy of a session on the computer -- that is, to somehow capture everything that appears on the screen (both input by the user and printed by the computer), and store it into a file (perhaps to be printed later). This process is sometimes called scripting.

One such situation is proving that your program works. In this case, you would want to save a copy of a user's session with the program, including what input the user gives and what output the program produces (which will hopefully agree with what it should output!).

The script program in UNIX
UNIX has a command for capturing these user sessions called script. To invoke it, enter

script filename

where filename is the name of the file to save the session to (not the name of the .cc file you are running!). For example, to store it in testruns.1, you would type

script testruns.1

Once you enter this, everything that appears on the screen will also be saved into the file you choose.

Ending the script
This will continue until you type:

^D     
(that is, you hold down the control key, and press the d key.)

This will end the scripting process and store the session in the file.

Do not forget to do this. The file will not be available to you until you type the ^D, and you may end up with a very large file if it contains (for instance) an editing session. In addition, if you invoke script while you are already doing a script, some very strange things can happen!

Printing the script
Once the script has been completed and stored into the file, you may then print it out, just as you would any other file. When you look at the results, you may notice some strange control characters. These are normal, as the script stores all characters that appear on the screen, including ^M (for line feeds) and ^H (for backspaces).