Reputation: 2209
I have a printer, an HP DeskJet 712C, shared via a Windows XP workstation. I am able to print to this printer from various applications, but I am unable to print to it (from the workstation the printer is attached to or any other) via the PRINT
shell command. I have a Perl script, currently hosted on a Windows 7 workstation, that generates text files. I would like those text files printed to the aforementioned printer, but as I am unable to use the PRINT
shell command, I don't know how. How can I print these text files to that printer in Perl?
Upvotes: 0
Views: 1813
Reputation: 27193
I don't know much about windows programming, but there are a couple of options I can think of.
Printer - There is a module on CPAN called Printer that claims to handle windows printing. I haven't used it. YMMV, but it looks like exactly what you want.
Wx - The Wx GUI toolkit has nice, windows compatible printing capabilities. It, sadly, is also a huge, complex dependency to add just for a simple command line script. I have used this and it works very nicely.
Win32::API - Here's where my Windows ignorance really shows. The Win32::API module lets you call into windows DLLs. If you know the appropriate functions/DLLs to use, you could access them to get a print job started.
Update
You might want to check out this thread on ActiveState's Perl-Win32 users' list.
Apparently you can just do:
open my $prn, '>', '//mycomputer/PrinterShare' or die "Oh noes $!";
print $prn "Here's some text to print.";
This is untested, untried, and maybe untrue, but give it a shot. What could possibly go wrong? Printers are cheap these days. ;)
Upvotes: 2