Friday, January 22, 2016

How to create a test print batch file on a Windows computer

Many network printers use a web interface to allow you to remotely monitor them and their status.  For some brands of printers, including Sharp and HP, you can send test print jobs from the printer's web interface to see if the device is functioning.  Other brands don't offer this capability, but if you have a Windows PC, you can use the LPR (Line Printer Remote) protocol and batch programming to set up your own test print program.

Create a new text file by right-clicking on your desktop, selecting New, and then Text File.  Designate this file as a batch file by saving it with the extension .bat.  You can name the program whatever you want -- testprint.bat, LPRtest.bat, etc. -- as long as it has the .bat batch file extension.

The same thing can be accomplished from the command prompt by typing:

edit filename.bat

The only difference that you'll notice by creating the batch file from the command prompt instead of from the desktop is that Microsoft's DOS text editor program will open, instead of Windows Notepad.  (If you want to open the file in Notepad from the command prompt instead of the DOS text editor, type notepad filename.bat instead.)

Copy and paste the following commands into your batch file:

@echo off
set /p printername= Printer to test:
lpr -S %printername% -P lp "test.txt"

Now save the batch file and open a new text file.  (This can be done from within the editor/Notepad by selecting New from the File menu.)  This file will be the file used to test printing, so you can type whatever you want here.  Something short and sweet like "test" is sufficient, but you can type whatever you want.  When you are done, save the file with the name "test.txt."  It's important to use this name so that your program can find the file.  Alternatively, you can modify the batch file to change "test.txt" to whatever file name you want to use.

Exit the program and make sure that both files -- the batch file and the text file -- are saved in the same directory.  Now you can test your program by double-clicking on it in Windows or typing the filename (with or without the ".bat" extension) from the command prompt.

A prompt will appear asking which printer you want to test.  Select a printer on your network to test by typing in either it's IP address or host name, then pressing ENTER.

You won't be notified if the print job is successful, so go to the printer's web interface before hitting ENTER to check the page count, then refresh the page to check it again shortly after sending the print job.  If the counter doesn't go up by one (which may take a minute or two for slower printers, or printers that need to warm up) the test print may have failed; otherwise, you can be reasonably sure it succeeded -- unless someone else printed one page at the same time that you sent your print job.

This test print program can be useful for remotely troubleshooting printing problems.  It bypasses the print driver, so it can also help to narrow down problems caused by a faulty, incorrect, or corrupted driver.

If you try to run the test print program and you get a message stating that the LPR command is not recognized, you probably just need to enable LPR on your PC.  This article will walk you through how to do that.

No comments:

Post a Comment