Hello,

I am attempting to print data from a variable directly to a CUPS printer - as opposed to a writing a hard-disk file and then sending it to the printer. The reason is because the file system will eventually be a read-only one.

I have created a file handle for the variable that stores the data and populated it. If I print the contents of $variable it is correct.

To send the data to the printer I am opening a file handle for reading and passing it as an argument to a CUPS printer.

However, I am getting a "No such file or directory" error. Yet, the variable and file handle both exist.

Does CUPS not accept a variable tied to a file handle as a parameter or (more likely) am I doing it improperly?

Thanks in advance.

#!/usr/bin/perl -t use strict; use warnings; use Net::CUPS::Destination; # Define Printer my $cups = Net::CUPS->new() or die $!; my $printer = $cups->getDestination("CITIZEN-CT-S801") or die $!; # Read Data my($variable)=''; open(my $fh, '>', \$variable) or die "Cannot open file for writing: $! +\n"; print $fh "Some data 1\n"; print $fh "Some data 2\n"; print $fh "Some data 3\n"; close($fh); # Print Data open($fh, '<', \$variable) or die "Cannot open file for reading: $!\n" +; if ($printer->printFile($fh, 'jobx')) { print 'Success';} else { my $error = $printer->getError(); if ($error) { print "Printer Error: " . $error . "\n"; } } close($fh); exit;

In reply to CUPS Printing - Using a Variable as a Filename by Wayne

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.