UP ONE LEVEL: ENCM 339 Fall 2001 Home Page

Recording a terminal session with termrec

Created for ENGG 333 in Fall 1995.
Updated for Fall 1996, again for ENGG 335 in Fall 1997 and Fall 1998, again for ENEL 339 in Fall 1999 and Fall 2000 and for ENCM 339 in Fall 2001
Last modified: Thu Sep 13 19:43:23 MDT 2001


Why record a terminal session?

In ENCM 339 in Fall 2001 starting with Lab 1 and perhaps in some other courses, the markers may need to look at a sample input/output record from a program in order to verify that the program works.

Making an input/output record may also be helpful when you are trying to debug a defective program. A printout of input and output may give some clues about where things start to go wrong. (However, it should be pointed out that a debugger like gdb is a much more powerful tool.)

[back to top of document]

Note to Fall 2001 ENCM 339 students

For ENCM 339 labs in Fall 2001, hand in input/output records only when you are specifically asked for them. Record only sample input/output from programs. Don't bother to do a pwd, print the date, cat the source file, recompile your program, etc., before running your program.

If you are using your own computer to do the assignments, you may produce an input/output record on your home machine. If you do so, there is no need to move your program back to the Linux lab to make and print a termrec file.

[back to top of document]

What are script and termrec?

script is a widely available Unix shell command for recording terminal sessions. script is somewhat user-hostile, so termrec was developed as a ``new and improved'' version of script. Please use termrec and not script for recording terminal sessions.

When you run termrec everything the computer sends to the terminal screen (prompts and program output, mainly) and everything the user types in (shell commands and program input, mainly) gets saved in a text file.

[back to top of document]

Starting termrec

The Unix shell command for starting termrec is
termrec file
where file is the name of the file you want to store the session record in. If you forget to specify file, the session record will be stored in a file called typescript.

After you start termrec, you get a new shell prompt, which contains <termrec> to remind you that termrec is running.

[back to top of document]

Stopping termrec

After you've successfully recorded a terminal session (or after you've made such a mess that you want to quit and start over) you stop termrec with the command exit. You should notice that the shell prompt returns to normal. Warning: if you type exit to the normal shell prompt, your xterm window will likely disappear.

[back to top of document]

An example termrec session

This example describes how a student might record an interactive session with the program for Exercise Z of Lab 99. (Don't panic--in reality, there will be only nine or ten labs.) She has already created the file adder.cpp:
#include <iostream.h>

int main()
  int a, b;
  cout << "Please enter a value for the int variable a: ";
  cin >> a;
  cout << "Please enter a value for the int variable b: ";
  cin >> b;
  if (!cin)
    cout << "\nI am sorry, but I could not read all your input." << endl;
  else {
    cout << "You entered "
         << a << " for a and " << b << " for b." << endl;
    cout << "The sum of those numbers is " << (a + b) << '.' << endl;
  return 0;
She compiles and links the program with g++w. Then she starts termrec to record an interactive session with the program. After running the program and exiting from termrec she uses more to display the record she has created. Below is a picture of the screen after all this has been done. There are annotations in the picture to help you distinguish actual prompts, commands, and program output from copies of prompts, commands, and program output stored in a text file. (Warning: The example is based on the 1997 configuration of the Common Core Linux systems, so in the ENEL lab in 2001 minor things, such as the shell prompt, may differ from what appears below.)

example use of termrec

[back to top of document]