Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Raw Data to Printer on Win XP

by dvergin (Monsignor)
on Sep 29, 2004 at 19:58 UTC ( #395119=perlquestion: print w/ replies, xml ) Need Help??
dvergin has asked for the wisdom of the Perl Monks concerning the following question:

Things have changed a bit since last I was programming in Windows.   :-/   (Has it really been 5 years??) I now find myself porting a Perl program from Linux to Windows XP that wants to output raw text to the printer. I can't figure out how to do it. In the olden days you could just print to LPT1 or PAR1 or some such. Also... it may matter that I am now looking at a printer on USB002.

I *could* rewrite the whole printing section of the current program, but it works fine in its own primitive way and I've got more pressing, more interesting things I'd much rather spend my time on.

SuperSearch and Google have led me to lots of interesting OT reads, but no solution. I'm beginning to doubt my Google-fu. I've brushed up on MODE. I've read the docs on several CPAN Printer modules. I've browsed for "pass-throuth" printer drivers. No help, no joy.

I'm certainly not the first person to want to do this! But how...

TIA
David

------------------------------------------------------------
"Perl is a mess and that's good because the
problem space is also a mess.
" - Larry Wall

Comment on Raw Data to Printer on Win XP
Re: Raw Data to Printer on Win XP
by terra incognita (Pilgrim) on Sep 29, 2004 at 20:12 UTC
    You can redirect the LPT1 physical port to a network printer. Here is an extract from msdn.
    To redirect print output for the LPT1 port to MyPrinter1 on print serv +er W2KPRN1: net use LPT1: \\W2KPRN1\MyPrinter1 To display information about the LPT1 port: net use LPT1:
      question is how to print raw data to printer -- NOT how to re-direct a port!!!! in the plethora of options for most decent printer drivers, you get an option to print RAW data, so that's accessed through the printer's control panel. then it's only a matter of actually sending the output to the printer...which i'm not too sure on.

        Hi,

        I think what you are looking for is for a perl module or code that allows you to print to the Windows Print API ... you can do so using Win32::Printer. You will also want to use Win32::Printer::Enum to determine which printers are available.

        hope this helps

        Jason L. Froebe

        No one has seen what you have seen, and until that happens, we're all going to think that you're nuts. - Jack O'Neil, Stargate SG-1

        Since the OP has "brushed up on MODE" which alows you to re-direct printer ports I figured it was on topic. You can often also FTP directly to the newer printers. Putting a file will cause a the printer to print it, it will also bypass the print server queue. :-)
        Of course that may not solve you problem either.
        Just my 2 cents.
      Well, yes. I had thought of that (or something similar). But:
           >net use LPT1:
           System error 2 has occurred.
      
           The system cannot find the file specified.
      
      And besides, the printer is not on the network. It's attached to USB002 on my laptop (which, to my frustration, lacks a parallel port). I had figured to use MODE to redirect LPT1 to USB002. But I could not make it work. Here's a MODE status request as an example of at least part of the problem:
           >mode LPT1: /status
           Illegal device name - LPT1
      
      It would be great if I could activate LPT1 and then redirect it to point at USB002. Any clues?

        Does your usb device show up as a COMn: port if you do just issue the "mode" command alone?

        If so, you can redirect LPT to it using

        Redirect printing: MODE LPTn[:]=COMm[:]

        Examine what is said, not who speaks.
        "Efficiency is intelligent laziness." -David Dunham
        "Think for yourself!" - Abigail
        "Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon
        mode /LPT1: /status should have been successful. On my system is replies that LPT1 is not redirected. Can you print at all (outside of Perl) from the CMD prompt? There have been issues in teh past with USB printing from the cmd line. If that is an issue you may have to update your drivers.
        HTH
Re: Raw Data to Printer on Win XP
by BrowserUk (Pope) on Sep 29, 2004 at 21:51 UTC

    I don't think there are any modules available to do this, but if you are prepared to drop to using Win32::API (or Inline::C or XS), then it is fairly simple to do using native calls.

    The code you would need is documented here.


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
    "Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon
      Hmmm... "it is fairly simple" for some definition of 'simple' involving 55 lines of example code. (Not all of which may be neccessary to my current purpose.)

      That's a little more work than I was hoping for, but I suppose I could get invested in doing that with Win32::API under the heading of "write once use many".

      But sheesh! All I want to do is squirt a few lines of text at the printer. Someone please take me back to linux and:

            echo "Hello World!" | lpr -oraw
      

      But anyway, thanks for the lead. If nothing more straight-forward comes to light. I'll probably end up using this approach.     Much gnashing of teeth is heard...

Re: Raw Data to Printer on Win XP
by traveler (Parson) on Sep 29, 2004 at 23:02 UTC
    terra incognita had the right idea even though id did not look like it. Use the net use command given, but put in the name of your local pc using quotes if your pc has spaces in its name. I know it looks funny, but that is the way. Then use net view \\hostname to see that it is there. Be sure to print the Control-Z at the end of the job to get the output to show up...

    HTH, --traveler

      Rapturous, demented gibbering and giggling fills the air...

      Success! Okay, let's doc this puppy.

      First, I took the trouble to go to

      Start / Settings / Printers_and_Faxes / Deskjet500 on US 
          / Printer / Properties / Sharing
      
      And clicked on "Share this Printer" and gave my printer a share name.

      Then, at a command prompt (mmm... command prompt, good!), the following did ensue:

      >net view \\GatewayM275
      Shared resources at \\GatewayM275
      
      Dv's Gateway M275
      
      Share name  Type   Used as  Comment
      -------------------------------------------------------------------------------
      DJUSB002    Print           DeskJet 500 on USB
      Printer     Print           Journal Note Writer
      SharedDocs  Disk
      The command completed successfully.
      
      >net use LPT1: \\GatewayM275\DJUSB002
      The command completed successfully.
      
      >net view \\GatewayM275
      Shared resources at \\GatewayM275
      
      Dv's Gateway M275
      
      Share name  Type   Used as  Comment
      -------------------------------------------------------------------------------
      DJUSB002    Print  LPT1     DeskJet 500 on USB
      Printer     Print           Journal Note Writer
      SharedDocs  Disk
      The command completed successfully.
      
      >echo Hello > LPT1:
      
      And the most beautiful sound did issue forth from my printer. Likewise for:
      >print test.txt
      

      Thanks to all who have contributed to this thread. My wife just called me to come home for dinner. I've blown much of the afternoon on this, but I'm outta here!

      ------------------------------------------------------------
      "Perl is a mess and that's good because the
      problem space is also a mess.
      " - Larry Wall

        OMG - all that to just "DWIM"...

        I'll make sure I give my Linux boxes an extra big hug before I go to bed tonight !!!

        use brain;

Re: Raw Data to Printer on Win XP
by schweini (Friar) on Oct 02, 2004 at 17:42 UTC
    since this seems to be a rather frequent problem, does anyone know whether there is some kind of "normal" solution for this in the works?
    I use open(PRN, ">COM1"), but is there no way of doing something like
    my $prn = Printer->new("Epson Stylus"); $prn->print_raw("foobar");
    or somethig along those lines? all this muddling around with network shares, port-redirection, etc. is nice and all, but somehow "suboptimal", IMHO.
    maybe there's a little program one can pipe text to, and that simply sends it to the printer raw-ly? anything?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://395119]
Approved by kutsu
Front-paged by kutsu
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2014-12-27 23:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (177 votes), past polls