question on Net::LPR / Unix::Login

H

Huub

Hi,

Running FC5, I'm not sure if this is the right place to ask, but I'm
trying Net::LPR to print to a remote printerserver. On CPAN I found nice
examples, but I get permission errors on the printer when I run my code.
Can I somehow 'su' to root from within Perl? Unix::Login only seems to
be for validating an existing login.

Thanks,

Huub
 
B

Ben Morrow

Quoth Huub said:
Running FC5, I'm not sure if this is the right place to ask, but I'm
trying Net::LPR to print to a remote printerserver. On CPAN I found nice
examples, but I get permission errors on the printer when I run my code.
Can I somehow 'su' to root from within Perl? Unix::Login only seems to
be for validating an existing login.

No, you can't. The only way is to run 'su' or 'sudo' with system.

Why do you think this is necessary? You are probably better off invoking
lpr(1) directly, and sendign the job as yourself.

Ben
 
H

Huub

No, you can't. The only way is to run 'su' or 'sudo' with system.

Ok.

Why do you think this is necessary? You are probably better off invoking
lpr(1) directly, and sendign the job as yourself.

If I want to send the job as myself, access is denied. Unless I print by
using the printmanager.
The script should print data from a 900 record database on paper. So if
I have to invoke lpr myself, I would have to print everything into a
file, and then print that file. This sounds like doing the print job
twice. Unless I can come up with another way to do it.
 
B

Ben Morrow

[ please attribute quotations ]

Quoth Huub said:
If I want to send the job as myself, access is denied. Unless I print by
using the printmanager.

....you mean, by using the lpr program? That is because that is how you
are supposed to print :).
The script should print data from a 900 record database on paper. So if
I have to invoke lpr myself, I would have to print everything into a
file, and then print that file. This sounds like doing the print job
twice. Unless I can come up with another way to do it.

You can pipe the data into lpr.

Ben
 
J

J. Gleixner

Huub said:
If I want to send the job as myself, access is denied. Unless I print by
using the printmanager.
The script should print data from a 900 record database on paper. So if
I have to invoke lpr myself, I would have to print everything into a
file, and then print that file. This sounds like doing the print job
twice. Unless I can come up with another way to do it.

Show us how you're sending the information to lpr.
 
H

Huub

Show us how you're sending the information to lpr.

use Net::LPR;

my $lp = new Net::LPR (
StrictRFCPorts => 1,
RemoteServer => '10.0.0.2 DeskJet520',
RemotePort => 515,
PrintErrors => 0,
RaiseErrors => 1,
);

my $data = " Contr. 2007\n
Min. bijdrage 4,25 euro per
jaar\n A.u.b. overmaken 15
juli 2006\n\n\n\n\nLidnr. $record Lidnr. $record \n
@straat @huisnr \n
@postcode @plaats \n\n\n\n\n\n\n\n\n\n\n\n";

$lp->connect() or die "Can't connect: ".$lp->error();

my $jobkey = $lp->new_job();

$lp->send_jobs('lp');
$lp->job_mode_text($jobkey);
$lp->job_send_control_file($jobkey);
$lp->job_send_data($jobkey, $data, length($data));

lp->disconnect() or die "Can't disconnect: ".$lp->error();


I've taken most of this from CPAN, assuming it is working code. Thank
you for helping out.
 
H

Huub

RemoteServer => '10.0.0.2 DeskJet520',
^^^^^^^^^^^
That doesn't look right. Try it with just the IP address or hostname,
but not both.

That is the server-IP followed by printqueue.
If the local system has a printcap definition for that printer, you
could just open a pipe to lpr and write the data there.

You mean like this?

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

This complains about not having any data to print. lpr wants the name of
a printjob, which I don't have.
 

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
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top