For Programmers: Free Programming Magazines  


Home > Archive > PERL Miscellaneous > February 2007 > Direct standard output to printer.









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Direct standard output to printer.
Doug Laidlaw

2007-02-23, 4:06 am

I have a Perl script (pcal) which prints to standard output. I didn't write
it.

The relevant line is $THECAL=`....'; print $THECAL;

I want to modify this line to print to the default (local) printer on lpr.
How do I go about this?

TIA,

Doug.
--
Books are good enough in their own way; but they are
a mighty bloodless substitute for life.
-R.L. Stevenson.

Sherm Pendley

2007-02-23, 4:06 am

Doug Laidlaw <laidlaws@dougshost.invalid> writes:

> I have a Perl script (pcal) which prints to standard output. I didn't write
> it.
>
> The relevant line is $THECAL=`....'; print $THECAL;
>
> I want to modify this line to print to the default (local) printer on lpr.
> How do I go about this?


Open a pipe to lpr and select it:

my $THECAL = '....';
open my $lpr, '|-', '/usr/bin/lpr'
or die "Could not open lpr pipe: $!";
select $lpr;
print $THECAL;

For details:

perldoc -f select
perldoc -f open

If you want to make only one or two prints go to lpr, instead of all of
them, you can specify the filehandle in the print:

print $lpr $THECAL;

sherm--

--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com