Have a Question?
Print

00565: Information and examples for printers, pipes, and spooling

Title:

Information and examples for printers, pipes, and spooling

Description:

The simplest case of using the spooler under the Unix operating system (assuming Unix 5.4) would involve the following entry in the BBx configuration file: 

ALIAS LP “>lp” “Spooler” 

This would alias the output pipe “>lp” to the device name “LP”. If everything worked right, this would spool output to the default printer of the user opening the device. Unfortunately, not everything will always go right and we have to account for such times. 

One of the things that can go wrong is that the spool file could grow too large for the disk and cause the spooler to fail. In the failure the spooler will likely generate an error. Typically, we wouldn’t want the user to see the error, preferring to report the “printer” failure ourselves (BBx will report an error on the channel opened to the running program). To avoid displaying the failure message, we’ll redirect the error output from the command to the null device (referred to as “tossing it in the bit bucket”) using the following change: 

ALIAS LP “>lp 2>/dev/null” “Spooler” 

This modification to the pipe makes the error output go to the null device. The error message goes away, but what happens when the user calls complaining of report after report failing when printed to the spooler? A simple change to the alias will allow for collection of the error messages: 

ALIAS LP “>lp 2>/tmp/lperror” “Spooler” 

This appends the error messages to a file called “/tmp/lperror”. If errors persist, someone could check this file for the cause of the errors. 

OK, now we have a device that accept output, spools it, and sends it to the default printer. What if you want to send it to a selected printer? This can (again) be performed using a small modification to the ALIAS line as follows: 

ALIAS LP “>lp -d printer 2>>/tmp/lperror” “Spooler” 

This change specifies the printer to the spooler as the printer or printer class named “printer”. This is useful if you want to output to a particular printer, but what if you would like to provide the user an option to select a printer or printer class? This, too, may be done using the following: 

ALIAS LP “>lp -d $DEST 2>>/tmp/lperror” “Spooler” DEST=any 

In this example, an argument in the pipe is replaced before it is executed. When BBx prepares the “system device name” in an ALIAS, it replaces the strings in the command or filename that start with a dollar sign, ‘$”, with the name found in the modes of the alias line. In the example above, BBx will see the “$” in the command and look up the name “DEST” in the configuration modes and, if it finds the string “DEST”, will replace it and the “$” with the data following the equals sign, “=”, in the modes. 

This replacement of arguments is particularly useful when you understand that you can specify the modes for a printer in the OPEN statement. Using the example above, the application could execute the following code fragment to spool to any named printer: 

Since the modes specified in the OPEN are passed before the options in the ALIAS line, any option given in both will be preferentially taken from the OPEN statement. In this example, the value of the string in P$ will be used in the pipe opened to access the spooler, and if the printer is opened without a MODE= in the OPEN (or not containing DEST=<string>) the value in the alias line will be used by BBx. 

Further use of the modes may be made by expanding the above to include a number of copies, form name, or special options to the spooler. As an example, the number of copies could b specified with the following extensions: 

ALIAS LP “>lp -d $DEST -n $COPIES 2>>/tmp/lperror” “Spooler” DEST=any, COPIES=1 

1010 INPUT (0,ERR=1010) “Printer name: “, P$ 
1015 INPUT (0,ERR=1015) “Copies: “,N(9); IF N=0 THEN GOTO 1010 
1020 OPEN (7,MODE=”DEST=”+P$+”,COPIES=”+STR(N),ERR=1010)”LP” 

(Note the commas, “,” between elements in the modes. The OPEN MODES= processing uses pretty much the same rules as the ALIIAS modes.) 

Spooling in other environments uses these capabilities as well. The Novell version of 4=”+STR(N),ERR=1010)”LP” 

(Note the commas, “,” between elements in the modes. The OPEN MODES= processing uses pretty much the same rules as the ALIIAS modes.) 

Spooling in other environments uses these capabilities as well. The DOS Novell versions of BBx will recognize: 

COPIES=<int>                  Number of copies to print (1-255, defaults to 1). 
FORM=<int>                  Number of the form to use (0-255, defaults to 0). 
LOCAL=<int>                  Which local printer to use(1-3, defaults to 3) 
QUEUE=<string>                  Which Novell print queue to use (default is the queue to which                           spooler 0 is assigned). 
SERVER=<string>                  Name of server controlling the desired printer (default is the current                           preferred server). 
LOGIN=<string>                  Required if the workstation is not already logged in. 
                          PASSWORD=<string> 
BANNER                           Causes a banner to precede the print job. 
BANNER=                  Like BANNER above, but also specifies the banner name. 
NAME=                           Used with BANNER= above. Specifies the user name to print on                           the banner (default is the current login). 
KEEP                           If the workstation disconnects abnormally, this option causes all                           data spooled thus far to print. Normally, the data is discarded in this situation. 

Any of these can be specified in the configuration file or in the MODES= in the OPEN statement. To use them, it is necessary to create one or more special ALIAS lines to the pseudodevice, NSPOOL. Here’s a typical example: 

ALIAS P1 NSPOOL “Novell Network Printer” SERVER=BASIS,QUEUE=PQ1 

Other special cases exist in printer configuration, such as printing to files and test printing. If you want to output a report to a text file for use elsewhere, it’s not necessary to modify the application, but instead you can supply a configuration entry as follows: 

ALIAS PFILE /tmp/file “File Output: O_CREATE, 0_TRUNC 

This will open the file “/tmp/file” as the output “device” and send all the printer commands to the file. Since we added O_CREATE and O_TRUNC, BBx will ask the file system to create the file and, if it already exists, to remove the data in the file before opening. Each open of the printer will clear the previous data so care should be taken not to allow multiple opens. Therefore, we’ll fix it to read: 

ALIAS PFILE /tmp/file “File Output” O_CREATE, 0_TRUNC,lock=/tmp/file.lck 

At the same time w added the familiar lock file to the configuration entry, we added an indicator to BBx that indicates the “printer” isn’t capable of handling form feeds. Thus, BBx will now use linefeeds to make the output to the printer paginate. Your report will never know what’s happening in the driver. So this would allow any report to be saved in a file. 

If you’re testing a report and simply wont to know if it executes correctly (without looking at the output) you could set up a “bit bucket” printer using the following alias: 

ALIAS PNULL /dev/null “Printer null” 

This device will accept all output and never complain, nor produce printed output. Be careful not to leave this on a production system as some user might be tempted to use it of the faster output, ignoring the loss of the printed report. 

RS6000 Spooling, Copies, Forms, options 

Set up the printer alias in config.bbx to open a pipe to the AIX “enq” command: 

alias LP “>enq -N $COPIES -P lp0” “Printer comment” CR, COPIES=1 

Within BBx: >open(1,mode=”COPIES=2″)”LP” 

The ‘mode=”COPIES=2″‘ on the OPEN will send the value 2 through to the AIX spooler command: ‘enq -N $COPIES’, replacing $COPIES with ‘2’. 

‘COPIES=int’ on the config.bbx alias line sets the default number of copies, which can be any integer and must be present; otherwise a system error will result on a normal OPEN, such as: 

>open(1)”LP” 

Additionally, BBx will check the user’s environment for a ‘COPIES=int’, which will override the default value set by ‘COPIES=int’ on the printer alias. 

‘-P lp0′ simply designates the destination printer’s queue name. Under AIX, /etc/qconfig contains printers’ queue names and their respective devices. For example: 

lp0: 
device = lp0 

in /etc/qconfig, the first queue defined becomes the default queue. If ‘-P xxxx’ is not present in the ‘enq’ command, then the default queue will be used. 

For special forms printing, ‘-M messagefile’ exists as an ‘enq’ command option, where ‘messagefile’ contains a special message to be sent to a specified operator’s console before the print job will print. The operator must respond to this message to continue or cancel the job. This allows a printer pause so that special forms can be loaded into the printer. 

For special forms with special permissions, set up a direct printer ali9as with EXECON an EXECOFF modes that execute the AIX ‘qadm’ command to: 1) stop the queuing process upon the OPEN of the printer channel; and 2) re-start the queue upon the CLOSE of the printer channel. An example of the config.bbx alias is: 

Alias LPX /dev/lp0 “comment” CR,EXECON=”qadm -D lp0:lp0″,EXECOFF=”qadm -U lp0:lp0″ 

‘qadm -D lp0:lp0’ disconnects the printer from the queuing system. Entering this command stops any ‘enq’ commands from being sent to the printer that serves the ‘lo0’ queue. If a file is currently printing, it is allowed to finish. You must have root user authority, or belong to either system group or printq group, to execute the ‘qadm’ command. Otherwise, a BBx ERROR 18 may result. The ‘qadm’ command works only on local print jobs. 

>.OPEN(CHANNEL)”LPX” 
>CALL “FORM.ALIGNMENTPROGRAM”,CHANNEL 
>CALL “PRINTCHECKS”,CHANNEL 
>CLOSE(CHANNEL) 

‘qadm -U lp0:lp0’ brings up the printer ‘lp0’ attached to queue ‘lp0’, and ‘enq’ commands are then re-started normally. 



Last Modified: 03/27/2000 Product: PRO/5 Operating System: All platforms

BASIS structures five components of their technology into the BBx Generations.

Table of Contents
Scroll to Top