WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Printing Information

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Printing to a LPT Port or UNC

Keywords:	 Printing DOS file  FileCopy LPT print spooler

Print same file to two seperate printers

Question:

How do I print the same file to two seperate networked printers?

Answer:

;Print the same file to two seperate printers
filetoprint = "C:\Temp\myfile.txt"
printer1 = "\\ServerOne\Laser5"
printer2 = "\\ServerTwo\Laser4"
FileCopy(filetoprint,printer1,0)
FileCopy(filetoprint,printer2,0)

FileCopy and Printing DOS files

Question:

How do I use FileCopy to print a DOS file?

Answer:

Use the FileCopy command and specify the destination as LPT1 or PRN. If you have a PostScript printer you'll need to send a formfeed in order to get it to print, and make sure you're sending a PS file.

Create the following DOS file:

From the DOS prompt create the file, put in a Form Feed (ASCII 12) and then end the file. Type:


  copy con: Printme.txt

  rem The following is the Linefeed character 
  ^L        

  rem The following is the Formfeed/Page Eject Character  (Alt+012)
  rem (Needed so that the printer will eject the page after printing)
  ^Z
Now your WinBatch Commands will be:
 
FileCopy(filename, "LPT1", @false)

FileCopy("printme.txt", "LPT1", @false) ;this file just has a form feed, to force the printer to print. 

Question:

I was wondering if there is a call in winbatch that will allow me to copy a file to LPT1.

For example, in dos, if you copy a text file to the lpt1, it print it [If printer is hooked up and so on] . I was wondering if there is such a thing in windows.

Answer:

If you just copy the file to the lpt port it should work - for local ports. The file must be in a format that the printer understands - most printers can handle plain text files. Postscript printers want postscript files. However if you can copy from DOS then it should work...

For local printers...

	FileCopy("xxx.txt","LPT1",0)
For network printers

FileCopy("xxx.txt","\\server\printername",0)

NB: In using this with network printers/LPT ports, the port must be directly mapped or the Capture command will not work.

Use w95AddPrinter or wntAddPrinter (the corresponding appropriate network extender functions) to map to LPT port.

If the Windows Capture of LPT1 will not work for you, but you can capture the port in DOS it successfully copies to LPT1, then you might want to hand this over to DOS via Winbatch, by invoking the DOS copy command to LPT1, specifically the 'capture' and 'send' commands.

PS -- 'capture' (and 'send /A=N') both required manually closing the DOS window when 'finished', so launching them via command.com (which has a command.PIF set up to "Close Window on Exit") will autoclose the DOS Window.

Ex:


RunHideWait("command.com", "/c send /A=N")
Here's a more detailed example:

coms = Environment("COMSPEC")
RunDOSCapture = Run(coms, "/c capture /q=.oper-01.mad /nt /nb /nff /ti=10 /l=1")
message("RunDOSCapture", "returned %RunDOSCapture%")

;construct the full path-and-filename and pass to DOS copy
FileStr1 = strcat(PortDrive,IdeeBatDir,"\import20.log")
RunDOSCopy = run(coms, "/c copy %FileStr1% lpt1:")

Another FileCopy to LPT Question:

Question:

I found that printing to LPT1 as above, e.g.

CopyWorkedA1 = filecopy("AA", "lpt1", @false)
will FAIL for the 1st such command [get "Error 1008: FileCopy Failed"].. then work ok for all [in my case, 2] subsequent such commands

[I put in a dummy 1st command -- i.e., printing a file I didnt really need, followed by the two 'real' ones.. then they printed.]

PS If @true is used as the third parameter ("warning",) then I get the "Confirm File Replace" window, asking whether I want to replace the file "lpt1" with "filename"..

Answer:

Printing to lpt1 is sometimes problematic - especially to network print queues.

I've had better luck copying to the print queue directly....


FileCopy("xxx.txt","\\server\prnter1",0)

FileCopy 1008 Error and Printing to Print Queue or LPT:

We have discovered that you can sometimes get a FileCopy 1008 error when printing to a LPT or print queue (UNC path) when the there is alot of network traffic. Especially if the print server is busy printing a large print job.

We are getting this error in a test script until the large print job was over, and after that the function worked without error.

FileCopy 1008 Error and Printer Systray Icons:

Question:

I'm getting the Error 1008 using Filecopy to LPT1 when printing to a locally-connected printer. I've checked my syntax, and all seems OK. I've run through the checklist with tech supt, and everything else seems OK also. Using most recent version of Winbatch, etc. etc.

Answer:

After much deliberation, we figured out that this user's problem had to do with some software that comes with some printers, that loads itself into the SYSTRAY. In this case, you have to remove this from the systray, and reboot your machine for the FileCopy function to work successfully.

For example, the HP LaserJet 5/5M printer comes with the HP JetPrint utility. In Windows 95, the HP JetPrint is available for both networked and directly connected printers. HP JetPrint is represented as a tray icon in the lower right hand corner.

For the FileCopy to LPT to work, remove this icon from the systray. Do this by right clicking on the icon in the systray, and then reboot.

Now the FileCopy to LPT1 will work.

To reinstall the HP JetPrint icon, go into Control Panel/Printers, and right-click the HP LaserJet icon in Explorer, and select the menu item to install the icon into the systray. Then reboot.

FileCopy to LPT Port with Novell 3.12 Network:

Question:

I wrote the following code to send a file to the printer.

tlogfile="test.txt"
FileCopy(tlogfile,"LPT1",@FALSE)
Exit
I'm getting FileCopy Error 1008. What am I doing wrong?

I'm on a Windows 95 system attached to a Novell 3.12 network. LPT1 is attached to the fileserver (Compaq PageMark printer).

Answer:

  1. Make sure LPT1 is mapped to the desired printer?

  2. Novell has LPT mapping problems with win95 sometimes. The Novell website has a number of articles on it. We've been having sporadic reports of this problem trying to copy a file to LPT1 mapped to Novell print queues.

    It turns out that if you execute the batch file from an extended filename directory, ie. "c:\Batch Files\" the filecopy will not work but if you rename the directory to a DOS 8 character name ie. "c:\BatchF\" it works fine. This problem exists in Netware only.

    WinBatch basically passes both the source and destination to windows. It looks like Windows might pass it to the network driver and then that keels over.


Article ID:   W13708
Filename:   Using FileCopy to Print to a LPT Port or UNC.txt
File Created: 2001:03:15:10:19:30
Last Updated: 2001:03:15:10:19:30