Re: [MacPerl-WebCGI] perl and printing on a printer

[email protected] (William Piel) Mon, 6 Jan 2003 18:12:35 -0500
Newsgroups perl.macperl.webcgi
Message-ID <[email protected]>
On Monday, January 6, 2003, at 03:39  PM, Eelco Alosery wrote:

> Hy,
>
> I'm using macosx 10.2.3 and I run my own webserver.
> Now I have a contact form whitch send's me the input to a e-mail 
> adres, but is it posible to print the input directly on my HP 
> ColorLaserJet 2500.
> I want to do it whith a cgi program, anny help is verry welcom.
>

First, make sure that your printer is listed with the Print Center 
utility.

Then check that BSD sees it by entering "lpstat -a" in the terminal. 
You can test print a document with the lpr command.

Now write your cgi script in the usual way -- the easiest thing is to 
copy the forms-processing script on page 1109 of "Mac OSX Unleashed" 
(John Ray and William C. Ray, Sams Publishing).

Suppose that your printer is called "myprinter" and suppose that the 
results that you want to print are stored in the array "@results".

Just end your cgi script with this:

open(LPR, "|lpr -P myprinter >/dev/null 2>&1");
   print LPR @results;
close(LPR);

Having "|" before "lpr" tells perl to open a command that expects 
input. The >/dev/null causes standard output to be discarded by being 
redirected to the null device. The 2>&1 causes standard error to be 
sent to where the standard output is sent, resulting in errors being 
discarded as well.

Bill