Wayne has asked for the wisdom of the Perl Monks concerning the following question:
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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: CUPS Printing - Using a Variable as a Filename
by Corion (Patriarch) on Aug 20, 2019 at 15:43 UTC | |
|
Re: CUPS Printing - Using a Variable as a Filename
by Fletch (Bishop) on Aug 20, 2019 at 15:43 UTC | |
by haukex (Archbishop) on Aug 20, 2019 at 15:46 UTC | |
|
Re: CUPS Printing - Using a Variable as a Filename (updated)
by haukex (Archbishop) on Aug 20, 2019 at 15:44 UTC | |
|
Re: CUPS Printing - Using a Variable as a Filename
by holli (Abbot) on Aug 20, 2019 at 16:35 UTC | |
|
Re: CUPS Printing - Using a Variable as a Filename
by Wayne (Novice) on Aug 20, 2019 at 16:54 UTC | |
by haukex (Archbishop) on Aug 20, 2019 at 21:47 UTC |