ARCHIVED: In Unix, how do I print a file to my local printer?

This content has been archived, and is no longer maintained by Indiana University. Information here may no longer be accurate, and links may no longer be available or reliable.

In Unix, you can use a utility called ansiprt in a pipe to print to your local printer. It wraps its input with the ANSI media-copy escape codes and spits it back out, trusting your terminal to behave correctly. You can use ansiprt to print any text files to your local printer by entering at the Unix prompt:

  cat myfile | ansiprt

Replace myfile with the name of the file you want to print.

If you are using a Unix host that does not have the ansiprt program, you can create a copy from the Perl script that follows. Save this text to a file named ansiprt in a directory named bin in your home directory (so that the full filename is ~/bin/ansiprt).

   #!/usr/local/bin/perl

   # ansiprint - print file/stdin to local printer via ANSI codes
   # (c)1994 Scott Hutton, Indiana University, UITS Support Center
   # usage: ansiprint [filename [filename ...]]

   @input = <>;
   $lines = @input;
   warn "Turning on printer...\n";
   print "\033[5i", @input, "\033[4i\n";
   warn "Turned off printer.  Output $lines lines.\n";

Once you've created a copy of the script, be sure to set the file permissions by entering at the Unix prompt:

  chmod 755 ~/bin/ansiprt

Note: Creating a copy of the ansiprt script in this manner won't work on Unix systems that do not have Perl installed.

At Indiana University, for personal or departmental Linux or Unix systems support, see Get help for Linux or Unix at IU.

This is document abye in the Knowledge Base.
Last modified on 2018-01-18 10:47:08.