http://qs1969.pair.com?node_id=800812

myuserid7 has asked for the wisdom of the Perl Monks concerning the following question:

I recently moved to CSW blastwave repositories - including perl.

I have a perl script that accepts a C program and does a pretty print to a network printer using lp().

The postscript is capture in a HERE doc.

$prolog = << ENDPROLOG; . . . A bunch of postscript. . . . ENDPROLOG $PRINT_CMD = '/usr/bin/lp'; $outcmd = "| $PRINT_CMD"; open(OUT,$outcmd); print OUT $prolog;
After upgrading perl the script is no longer printing the postscript but is printing the postscript code.

I was wondering if someone could point me to a better way.

Replies are listed 'Best First'.
Re: piping to lp is broken after perl upgrade
by moritz (Cardinal) on Oct 12, 2009 at 22:29 UTC

    You should check if open was successful, and also if close was:

    open my $output, '|-', $PRINT_CMD or die "Can't open pipe to $PRINT_CMD: $!"; print $output $prolog; ... close $output or warn "Error while closing pipe to $PRINT_CMD: $!";

    Maybe that'll give you some clue about what's wrong.

    Perl 6 - links to (nearly) everything that is Perl 6.
      I got excited when I saw your close - I thought for sure the open handle was causing the grief.

      Added the error checking. Nothing.

      Something is foobar here and I am not sure it is perl. Even from the command line...

      cat foo.ps | /usr/bin/lp -o nobanner
      prints the postscript code while...
      /usr/bin/lp -o nobanner foo.ps
      Prints the postscript document. So I really can't expect my perl script to work as written.
Re: piping to lp is broken after perl upgrade
by GrandFather (Saint) on Oct 13, 2009 at 00:34 UTC

    I don't see an issue in the code you've shown except that you're not using strictures (use strict; use warnings;). It wouldn't surprise me a great deal to find that there is something that was waiting in your heredoc to bite and has now bitten. It may help if you:

    my $prolog = << 'ENDPROLOG';

    so interpolation doesn't happen.


    True laziness is hard work
      Thanks for your reply.

      I created a files called test.ps.

      $ cat test.ps %!PS /Courier findfont 20 scalefont setfont 72 500 moveto (Hello world!) show showpage
      If I send it to the printer, it works. I get a Hello World.

      So here is a recreation of the script that is failing.

      #!/opt/csw/bin/perl -w use strict; use warnings; my $prolog = <<ENDPROLOG; %!PS /Courier findfont 20 scalefont setfont 72 500 moveto (Hello world!) show showpage ENDPROLOG my $PRINT_CMD = '/usr/bin/lp -o nobanner'; open my $output, '|-', $PRINT_CMD or die "Can't open pipe to $PRINT_CMD: $!"; print $output $prolog; close $output or warn "Error while closing pipe to $PRINT_CMD: $!";
        I ended up abandoning the use the csw perl for this script. Instead, I pulled the 5.8.9 source and complied it on my Solaris 10 machine using gcc4.

        I pointed the test script at the new compile and it started working.

        Sadly, I am not that confident in the blastwave perl now. Surely just paranoia but once bitten...