Link to home
Start Free TrialLog in
Avatar of rustycampbell
rustycampbell

asked on

How to print a text file to a shared printer from cmd

I need to print a text file with a computer using a printer shared on a network.

I tried print /d:\\softailcustom\clp610 invoice.txt

When it's on the machine with the printer it works, but when it's on another machine it doesn't even though the same computer will print using windows printing.

I get "unable to initialize device" error
Avatar of Tony Giangreco
Tony Giangreco
Flag of United States of America image

Try print invoice.txt > \\server\printer-name
Avatar of rustycampbell
rustycampbell

ASKER

I get unable to initialize device PRN
If it's a laser printer, you probably won't be able to do it.  What printer are you using?
It's a laser but...

1. I get the same behavior using a dot matrix printer
and
2. It works on the computer the printer is on even with the laser printer.
A few steps are needed and it should print.

Assumptions:
 
  1- This is being attempted on a Windows PC (XP, 7, etc)
  2- A Windows printer that is printing to the desired network printer is already defined and functioning properly
  3- The print command in use is the DOS print command


Resolution:
 
  1- Enable printer pooling to make the Windows printer available within DOS
        a- Open the "Printer properties" of the desired network printer
        b- Go to the Ports tab
        c- Check the box for "Enable printer pooling"
        d- In the window where you select the network port, scroll all of the way to the top of the list and select (check) LPT1:.  
            Do NOT uncheck your current network port.  This will mean that there are now 2 ports enabled (checked) for this printer. (The network port and LPT1:)
        e- Click on Ok to save the changes

  2- Use the following command
        print /d:lpt1 invoice.txt
this works on the computer that has the printer attached, as does
print /d:\\softailcustom\clp610 invoice.txt

It still doesn't work on the network computer.

This has changed some behavior. When I try type or copy to lpt1, instead of access denied, I get the system cannot find the file specified.
On the workstation which is issuing the print command, you probably need to invoke the net use command, to associate the target printer share with LPT1:.

net use LPT1: //computer-name/printer-share-name

where:
//computer-name is the name of the workstation which 'owns' the target printer.

//printer-share-name is the share name (preferably 8 characters or less) of the target printer on that workstation.
tried the net use command, it appeared to work, but did not change the behavior of the print/type/copy commands.
Where does the file reside that you are wanting to print?

Did you specify the full path to the file?
    print /d:lpt1 full pathname\filename

If the file is located on a network share, you may need to map a drive to it first so the print command can find the file
    net use m: \\servername\sharename\path /persistent:yes

Open a cmd prompt, go to the drive letter m: and if you can see invoice.txt, you should be good to go

Then use
    print /d:lpt1 m:\invoice.txt
To keep things as simple a possible, I moved the current dir of cmd.exe to the dir of the file. It seems to be grabbing the file OK. When I try to copy it to the printer, I also copy it to a new file name just to check on it, and that works.
ok, sorry but I'm confused.

  1- I thought that we were working with the Print command, but now we are copying to the printer, so I assume that you are using Copy filename >lpt1.
  2- The error reported after enabling printer pooling said that the specified file could not be located, but a copy from the same cmd prompt works.

Clarification please:
   I was assuming that you were using the Print command for a particular reason but now that you are mentioning using the Copy command, I am curious as to the desired goal.
   Is the goal simply to take the invoice.txt file and send it to a networked printer via a script or command line function?
   If that is the goal, please list the OS versions of the networked workstation and of the server/workstation that is hosting the printer and I can provide a detailed solution.
Avatar of David Johnson, CD
one item that may be a gotcha is that a laser printer is a page printer not a line printer, after printing from dos you need to send a form-feed or it will keep waiting for input for the page.
Some printers (host-based printers) do not understand simple text, and sending them a page of text will produce absolutely nothing.

What is the printer model?
It's a Samsung CLP-610. It will print the file as a local printer. While
there does seem to be a difference between the laser and the dot matrix,
it appears to be more of a networking issue.

While working on this, I have been able to get the dot matrix to work on some
computers but not all.
The solution is easily obtained but I need some additional information to provide detailed instructions.
  1-  The OS version of the computer named softailcustom that is hosting the printer
  2-  The OS version of the computer(s) needing to print to softailcustom\clp610

       (Windows XP, 7, 8, Windows Server 2000, 2003, 2008, 2008 R2, etc.)
1. windows 7
2. windows 7
ASKER CERTIFIED SOLUTION
Avatar of eerwalters
eerwalters
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Kudos sir... thank you.