Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Printer module from web interface

by ksublondie (Friar)
on Mar 07, 2011 at 23:02 UTC ( #891923=perlquestion: print w/replies, xml ) Need Help??
ksublondie has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks!

I'm needing to use the Printer module on a linux web server. If I try to print from a script run from the command line it works like a charm. However, if I try that same code (actually the same file, not just a copied portion of the script somewhere else),

my $prn= new Printer('linux' => 'lp'); $prn->print($text);
I get the following error:
Internal exception error - Insecure $ENV{PATH} while running with -T s +witch
I'm not a linux expert. I only know enough to be dangerous. I've tracked it down to failing at the following line:
open PRINTER, $pr_cmd or Carp::croak "Can't open printer connection to $self->{'printer'}{$OSNAME} +: $!";
in the print sub inside Printer::Unix. Any ideas on how I can get this to work?

Yes, I need to be using a specific printer from the server, not the locally installed printers on the workstation.

Replies are listed 'Best First'.
Re: Printer module from web interface
by GrandFather (Sage) on Mar 07, 2011 at 23:39 UTC

    You've hit a Taint issue. How is $pr_cmd formed? You should be able to untaint $pr_cmd by running it through a regex match and using a matched string as the value for $pr_cmd.

    True laziness is hard work
      $pr_cmd is set in the Printer::Unix module:
      my $pr_cmd = "| lpr -P $self->{'printer'}{$OSNAME}";
      I've added:
      $pr_cmd=~/^(.*)$/; $pr_cmd=$1;
      and I've even tried hard-coding $pr_cmd="| lpr -P lp" but I'm still getting the same error. Interesting observation:
      open PRINTER, $pr_cmd or warn "Can't open printer connection to lp: $!";
      Doesn't show my warning text. Is that to be expected?

        Oh!. Maybe you need to untaint $ENV{PATH}. If it's used by open, which is likely, then you'd get that error and your script would die horribly before hitting the warning.

        True laziness is hard work
Re: Printer module from web interface
by wind (Priest) on Mar 08, 2011 at 00:17 UTC

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://891923]
Approved by Perlbotics
Front-paged by MidLifeXis
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2018-02-19 00:48 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (257 votes). Check out past polls.