in reply to Trying to Print a File

Is this "so simple" in other cross-platform interpreted languages? It's a challenge because every platform handles printing in a remarkably different manner.

Sometimes it is simple in Perl, like on Unix:

#Send raw data to printer on Parallel Port 0: open PRINTER, '>>', '/dev/lp0'; print PRINTER $data; close PRINTER; #Send data to lpd for printing open PRINTER, "|lpr -P $printer"; print PRINTER $data; close PRINTER;

It's more difficult on Win32 and some other systems, because there are not convenient device files and scriptable print programs to work with. This isn't a shortcoming of Perl, it's a shortcoming of an OS that requires a plethora of system-library hooks just to print.


<<UPDATE:
Corion points out that Win32 systems can use the 'LPTn:' "special files", which work much like /dev/lpN files in *NIX. And, it appears that W2K finally has a scriptable print-spool command as well.

So, I stand corrected: Perl can easily print on many an OS with ease, so the main question shows more a lack of understanding of the underlying OS than an issue with Perl.
UPDATE ;


As an aside, you're fortunate I'm in a good mood today, otherwise I doubt you'd get an answer -- your comment is inflamatory, and you've asked for replies to your e-mail address. The former is just rude when you're asking for help, and the latter is both rude and unadvisable unless you want your Hotmail account filled with more Spam than usual. It's not like Google and other search engines don't index the Monestary, you know...

radiantmatrix
require General::Disclaimer;
"Users are evil. All users are evil. Do not trust them. Perl specifically offers the -T switch because it knows users are evil." - japhy

Replies are listed 'Best First'.
Re^2: Trying to Print a File
by Corion (Patriarch) on Nov 05, 2004 at 20:02 UTC

    The Win32 part is not exactly true:

    open LPR, ">LPT1:" or die "Couldn't open printer"; print LWP <>;

    Will print out a text file on the printer, much like the lpr command. Of course, there are no fancy postscript interpreters behind that... But printing any non-trivial file under Windows 2000 or higher can be done with the following, provided that there is the appropriate registry entry for the file type:

    my $file = 'foo.xls'; system("print $file");