Script Command

The Script command is used when you are satisfied with your program and the output. You may need to prepare a hard copy of your program AND its result to hand in. To get a hard copy of the output, you need to use Script command to store the output in a file and then print it out. The following procedure shows you how to do it:
  1. Type whoami command. This tells if it is the correct account.
  2. Type pwd command. This command displays the current directory.
  3. Type ls command. This command displays the content in the current directory.
  4. Type cat filename.cpp This command captures the C++ program.
  5. Compile your C++ program. That is necessary to prove that your program compiles cleanly.
  6. Capture your C++ program output. You need to do this immediately after the compilation, to prove that the output of the program came from the cleanly compiled file.
You will need to hand in a copy of your C++ program and the output of the Script command for your class assignments. For example, if your program name is hello.cpp the convention is to tell Script to use hello.log as the name for the output it produces. The following example demonstrates how to use the script commamd.
hercules[25]% script hello.log
Script started, file is hello.log
Script on hercules[1]% whoami
Script on hercules[2]%pwd
Script on hercules[3]%ls
Script on hercules[4]%cat hello.cpp

#include <iostream>
using namespace std;

int main() {

  string user_name;

    cout << "Welcome to the world of C++" << endl;
    cout << "What is your name? ";
    cin >> user_name;
    cout << endl;
    cout << "Hi " + user_name + "! Welcome to CS110 class." << endl;
  return 0;
} // end main

Script on hercules[5]% CC hello.cpp -o hello
Script on hercules[6]% hello
Welcome to the world of C++
What is your name? Ada

Hi Ada! Welcome to CS110 class.
Script on hercules[7]% exit
Script done, file is hello.log

At the end of script process, the exit command is used to close the process of script. Always remember this --- WHEN YOU USE script YOU MUST ENTER exit AT THE END!!! In this example, hello.cpp is the C++ source file, hello is the executable file, and hello.log is the output from the Script. The printout for the C++ source code and the Script output will be required for your class assignment.

Once you are done your script, take a look at your hello.log file. This file has all the requirement for handing in your assignment.You will see the file has time stamp on it.

Copyright: Department of Computer Science, University of Regina.