VanDyke Software

Tips

Index

Note: This tip is for use with SecureCRT® for Windows®.

Using Pass-Through Printing More Effectively with Perl Scripts

You may be a programmer looking for a quick and easy way to print source files directly to your local printer. Or perhaps you are developing an in-house application and want to roll out a mechanism for end users to print directly from their terminal to a desktop printer.

Sometimes remote applications don't support pass-through printing or you need to modify the process in some way. A customized script, such as the Perl script example in this tip, can be an effective solution.

The script notes provide you with all of the escape sequences for the emulations supported by SecureCRT®. The script shows you a simple example of how to use the escape sequences, which you can modify or build on to suit your particular needs.

To try out this script, you'll have to select the appropriate modification for your emulation and specific needs, then decide whether to send the output to the printer, the screen, or both.

Once the script is on the remote host, simply cat the file you want to print and pipe it to the script. When the script stops receiving data, it will send the output to SecureCRT, which then handles sending the file on to the selected printer (you can also print to a text file ). The script buffers all of the data, so you don't need to worry about printing one line per page.

Pass-through printing is turned on by default in SecureCRT. To make sure it is turned on for a particular session, go to Session Options / Printing. The Disable Pass-Through Printing option should be disabled. You should also make sure that the Buffer Pass-Through Printing option is disabled.

Here is the sample Perl script for pass-through printing in its entirety: ptp.pl.txt (for this script to work properly, you should save the file without the .txt extension).

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Begin ptp.pl ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#!/usr/bin/perl
# ptp.pl
# this script will turn on pass-through printing, print data received
# on STDIN, and then turn off pass-through printing.
# These are the escape sequences used by the various terminal emulations
# that SecureCRT support. Uncomment $pcon_on and $pcon_off specific to
# your emulation.
# For VT100, VT102, VT220, ANSI, Linux, SCOANSI, XTERM
#    printer controller escape sequences (sends information to the printer
#    only)
$pc_on = "\033[5i"; # <esc>[5i
$pc_off = "\033[4i"; # <esc>[4i
#    auto print escape sequences (sends information to the printer and to
#    the screen
# $pc_on = "\033[?5i"; # <esc>[?5i
# $pc_off = "\033[?4i"; # <esc>[?4i
# For Wyse50
#    transparent print mode escape sequences (sends information to the
#    printer only)
# $pc_on = "\030"; # <ctrl>X
# $pc_off = "\024"; # <ctrl>T
#    auxiliary print mode escape sequences (sends information to the
#    printer and to the screen)
# $pc_on = "\022"; # <ctrl>R
# $pc_off = "\024"; # <ctrl>T
# For Wyse60
#    transparent print mode escape sequences (sends information to the
#    printer only)
# $pc_on = "\033d#"; # <esc>d#
# $pc_off = "\024"; # <ctrl>T
#    auxiliary print mode escape sequences (sends information to the
#    printer and to the screen)
# $pc_on = "\022"; # <ctrl>R
# $pc_off = "\024"; # <ctrl>T
# get the data to send to the printer from STDIN
@input = <>;
$lines = @input;
# print the data
print "pass-through printing on\n";
print $pc_on;
print @input;
print $pc_off;
print "pass-through printing off\n";
print $lines, " lines printed\n";

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ End ptp.pl ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~