I can think of a couple of ways, one I've tried, one I haven't (yet... .<br>
<br>
First method...<br>
<FONT FACE=monospace><br>
open (MYFILE, ">/tmp/myfile.txt"<br>
.<br>
... Do some perl stuff writing to MYFILE.<br>
.<br>
close(MYFILE);<br>
system("lp -dmyprinter /tmp/myfile.txt"<br>
unlink("/tmp/myfile.txt"<br>
</font><br>
Second method, that you suggested, which I haven't tried yet, but that should work a treat...<br>
<FONT FACE=monospace><br>
# Use -s to silence lp.<br>
open(MYPRINTER, "¦ lp -s -dmyprinter"<br>
<br>
.<br>
... do some perl stuff writing to MYPRINTER.<br>
.<br>
<br>
# If this works as I suspect, print job should start now...<br>
close(MYPRINTER);<br>
</font><br>
2nd way is a lot neater - wish I'd thought of it myself a long time ago! <br>
<br>
OK, I'm off to try this now - I'll let you know how I get on
Works well - as in the following example:<br>
<FONT FACE=monospace><br>
#!/usr/bin/perl<br>
<br>
opendir(HOME, $ENV{'HOME'});<br>
<br>
open(PRINTER, "¦ lp -s -dmyprinter"<br>
<br>
while ( $file = readdir(HOME) ) {<br>
print PRINTER $file, "\n";<br>
}<br>
<br>
close(PRINTER);<br>
<br>
closedir(HOME);<br>
</font><br>
<br>
Just replace the <FONT FACE=monospace>lp</font> command with something appropriate for your system.<br>
<br>
HTH.
Andy's second suggestion is the way we do things - works fine unless you want to keep a copy of stuff you've printed.<br>
<br>
Mike<br>
<p>Mike Lacey<br><a href=mailto:Mike_Lacey@Cargill.Com>Mike_Lacey@Cargill.Com</a><br><a href=
Couple of years back posted a thread in tek-tips ..regarding
printing in perl .
thread219-7086
i tried the same thing ...but its not working for me ..I really
appreciate if you could tell me what i am doing wrong.
Here is the code i used to
$variable_to_print="abasdhajsd";
open(PRINTER,"¦lpr -PPrintServer01" || die "Can't open lpr: $!\n";
print PRINTER $variable_to_print;
close(PRINTER);
Printer didn't respond to this code.....
when i changed the code to write to a file and then print it ..it
worked ....
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.