Print file via batch
brucine Posted messages 24849 Registration date Status Member Last intervention -
Hello, I am trying to print a text file using batch but I can't get my code to work, here it is:
print /d:COM4 : C:\Users\Utilisateur\Downloads\gedgege.bat
1 answer
-
Hello,
Assuming the port is correct and the printer is reachable through it, the PRINT command only prints text files (and even then, subject to ASCII characters).
Therefore, one must either cheat by using a program that prints itself via the command line, here through Notepad:
RUNDLL32 PRINTUI.DLL,PrintUIEntry /y /n "%printer_name%" start /min notepad /P filename.txt
Or use a dedicated utility, search for "Batch Windows Print Batch File," Van Der Woude also describes a number of examples using the contextual option of a specific "print" extension, via the Windows interface or the registry:
https://www.robvanderwoude.com/printfiles.phpThe "name" of the printer is retrieved, for example, by a WMIC command and can then be sent to a variable:
https://stackoverflow.com/questions/32595421/is-it-possible-to-send-a-file-to-a-printer-with-a-batch-file