Notice! This document is currently in Archived status.
The content of this document may be incorrect or outdated.

Print this article Edit this article

Capturing output for printing

There are several ways to capture your program's output in a file.

The first way is to use "output redirection". The redirect command (>) will redirect the output from the program into a file. If your program does require you to type in data at the keyboard you will not see the prompts.

	  a.out > outdat
This method puts output into a file named outdat. The file can then be printed using the lp command:
	  lp outdat
To view the file use the cat or more commands:
	 cat outdat
more outdat

The same data may be routed directly to the printer without storing it in a file. This is done using the pipe (|) character to direct the command output to another device:

	 a.out | lp
If you need to enter data from the keyboard, you probably want to use the script command. Script makes a copy of everything that is printed on your terminal. To use script, type this command:
	script foo
The machine will respond:
	Script started, file is foo
Then run your program. When the program is done, type:
	exit
The machine will respond:
	Script done, file is foo
You can then view the file on your terminal screen or print the output file on a printer, just as you would any other file.

Last Modified: Dec 19, 2016 11:12 am US/Eastern
Created: May 31, 2007 1:22 pm GMT-4 by admin
JumpURL: