question on printing to /dev/lp

H

Huub

Hi,

I want to print my output to a printer and not to screen. In the FAQ I
read about filehandles. Do I open printers the same way as files or
differently? And how about ejecting a sheet from the printer? Is there a
command for it?

Thanks,

Huub
 
B

Ben Morrow

Quoth Huub said:
I want to print my output to a printer and not to screen. In the FAQ I
read about filehandles. Do I open printers the same way as files or
differently? And how about ejecting a sheet from the printer? Is there a
command for it?

The usual way to print on Unix systems is to open a pipe to lpr(1) or
lp(1) (depending on which you have). Read the manual to find out what
data formats they accept: commonly, you must convert your output to
PostScript. You can do this with the program a2ps (among others); this
will convert a form-feed ("\cL") into a new page.

Ben
 
H

Huub

The usual way to print on Unix systems is to open a pipe to lpr(1) or
lp(1) (depending on which you have). Read the manual to find out what
data formats they accept: commonly, you must convert your output to
PostScript. You can do this with the program a2ps (among others); this
will convert a form-feed ("\cL") into a new page.

Ben

Sorry, but I don't fully understand it. You're mentioning pipe, but when
I read "man perlfunc", it seems there's no way to really print to a
(network)printer from the script. As I understand I have to print to
file first, and then to a printer. Is this correct?
 
B

Ben Morrow

Quoth Huub <"v.niekerk at hccnet.nl">:

[ please attribute quotations ]
Sorry, but I don't fully understand it. You're mentioning pipe, but when
I read "man perlfunc", it seems there's no way to really print to a
(network)printer from the script. As I understand I have to print to
file first, and then to a printer. Is this correct?

No. You have to open a pipe lpr(1) or lp(1). If you don't understand
this statement you need to find out more about how your OS works before
you try programming for it; and, as I said, you need to find out what
data formats your print spooler will accept.

Ben
 
H

Huub

No. You have to open a pipe lpr(1) or lp(1). If you don't understand
this statement you need to find out more about how your OS works before
you try programming for it; and, as I said, you need to find out what
data formats your print spooler will accept.

Ben

I think I got it. You mean e.g. open(OUTPUT,'|/dev/lp0'), where '|' is
the pipe.
 
B

Ben Morrow

Quoth Huub said:

[ please attribute quotations. next time you'll go in the killfile. ]
I think I got it. You mean e.g. open(OUTPUT,'|/dev/lp0'), where '|' is
the pipe.

No, I don't. I mean e.g.

open my $LPR, '|-', qw/lpr -Pprinter/ or die "can't fork lpr: $!";

but with the appropriate syntax for the lpr(1) or lp(1) on your system.
Please learn how printing works on your system before trying to do it
from Perl. As I said, on most Unixen printing is through one of the
*programs* lpr or lp; but the syntax and accepted formats vary.

Ben
 
H

Huub

No, I don't. I mean e.g.
open my $LPR, '|-', qw/lpr -Pprinter/ or die "can't fork lpr: $!";

but with the appropriate syntax for the lpr(1) or lp(1) on your system.
Please learn how printing works on your system before trying to do it
from Perl. As I said, on most Unixen printing is through one of the
*programs* lpr or lp; but the syntax and accepted formats vary.

Ben

I know how to deal with printing on Linux and BSD. Using apsfilter and
lpr. Just with Perl it's new to me. Thank you.
 
S

Sherm Pendley

Huub said:
I know how to deal with printing on Linux and BSD. Using apsfilter and
lpr. Just with Perl it's new to me. Thank you.

And now for something completely different... :)

Have you had a look at the various CUPS modules on CPAN?

sherm--
 
H

Huub

No, I don't. I mean e.g.

open my $LPR, '|-', qw/lpr -Pprinter/ or die "can't fork lpr: $!";

Reading CPAN on open & pipes, I still don't quite understand it. I
assume $LPR is the data to be printed, printer is of course the
printerqueue. But where do I put the filename? I suppose I completely
miss the point somewhere.
Thank you for helping out.
 
D

David Squire

Huub said:
Reading CPAN on open & pipes, I still don't quite understand it. I
assume $LPR is the data to be printed

No. $LPR is the filehandle that is bound to the pipe.

, printer is of course the
printerqueue. But where do I put the filename? I suppose I completely
miss the point somewhere.

There is no filename. You have a pipe, not a file. Anything you print to
the filehandle $LPR will be sent via the pipe to the command 'lpr
-Pprinter'.

Consider this command line version:
cat myfile.ps | lpr -Pprinter1

Here the output of the command 'cat myfile.ps' is piped into the input
of the command 'lpr -Pprinter1'.

HTH,

DS
 
H

Huub

No. $LPR is the filehandle that is bound to the pipe.
OK.

There is no filename. You have a pipe, not a file. Anything you print to
the filehandle $LPR will be sent via the pipe to the command 'lpr
-Pprinter'.

Consider this command line version:


Here the output of the command 'cat myfile.ps' is piped into the input
of the command 'lpr -Pprinter1'.

So if I put the open function first, and then this:

print($LPR," Contr. 2007\n");

it should pipe the string to the printer?
 
D

David Squire

Huub said:
So if I put the open function first, and then this:

print($LPR," Contr. 2007\n");

it should pipe the string to the printer?

Close, but you have the syntax for using filehandles with print wrong.
It should be:

print $LPR "Some string";

The comma will break it... this stuff is in the documentation: perldoc
perlfunc

.... and of course, as others have said, you have to send the printer
something it can understand, e.g. postscript.


DS
 
H

Huub

Thank you very much. The print command was something I thought had taken
from CPAN, but now it's working. The printer accepts ASCII, so all is
finally working. Thank you (all) for your patience.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,176
Messages
2,570,947
Members
47,498
Latest member
log5Sshell/alfa5

Latest Threads

Top