lprint "Helping Hand Acceptance Corporation" lprint lprint "Save this portion for your records"might be executed as follows:
$ LPR="lpr" $ export LPR $ a.out $The following will arrive at the line printer via the line printer spooler:
Helping Hand Acceptance Corporation Save this portion for your records
$ LPR="lpr" $ export LPRprior to the execution of user’s program will see that the output to the "printer" with lprint is sent via "lpr." On the other hand, if a dedicated spooler line, say "/dev/tty11," is available, the shell commands:
$ LPR="cat -u >/dev/tty11" $ export LPRprior to execution of the user’s program will see that the output to the "printer" with lprint is sent directly to this line.
Other printer arrangements can always be accommodated by an appropriate LPR command. Note that these examples are appropriate for the ordinary UNIX shell "sh" or Bourne shell. The syntax for setting and exporting environment variables under the Berkeley shell "csh" is different.
Some printer applications require that output appear without delays due to buffering. Basmark QuickBASIC introduces no buffering of its own, however, this does not guarantee that buffering will not be performed by the user’s LPR command. A spooler will always introduce buffering. Even "cat" will cause some buffering unless it is used with the "-u" switch, as in the example above.
Conceptually, the line printer may be regarded as a static, omnipresent facility. Most applications are well served by this model, however, applications which need to circumvent the buffering introduced by a spooler or need to dynamically redefine the LPR command require a more detailed model: The line printer is merely a communication channel, much like a file, except that the output is sent to an executing program (the LPR command). And while a file is opened and closed by explicit statements, the line printer channel is opened implicitly by the first lprint statement. At this time, the LPR command is read and invoked. The channel is closed only upon termination of the BASIC program. Only then is the command signaled that output is complete. Thus if a spooler buffers the output, physical printing will not begin until the BASIC program terminates. Also, redefining the LPR command does not redirect the output.
These problems could be circumvented by the means to explicitly close the line printer channel. Buffered output would then be flushed. The LPR command could be redefined and the next lprint statement would implicitly reopen the channel. A special routine is provided in Basmark QuickBASIC to close the line printer as demonstrated in the following program:
environ "LPR=cat >file1" lprint "this goes to file1" call lclose environ "LPR=cat >file2" lprint "this goes to file2" call lcloseThe two messages are sent to their respective files. The call lclose statements close the line printer and permit the redefinition of the LPR command. Note that the last statement is unnecessary because of the implicit closing upon termination. Also note that familiarity with the call statement is unnecessary here because these statements must be coded exactly as they appear and no additional coding nor special compiling command is required.
from The Basmark QuickBASIC Programmer’s Manual by Lawrence Leinweber