Print file via batch

Pierre -  
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

  1. brucine Posted messages 24849 Registration date   Status Member Last intervention   4 170
     

    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.php

    The "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

    0
    1. brucine Posted messages 24849 Registration date   Status Member Last intervention   4 170
       

      If you want to test the PRINT command on a standard text file, it might be quicker to redirect each line of the file to a temporary text file that is deleted at the end of the operation: MyCommand > FilePath.txt

      Or to do it all at once: TYPE Toto.bat > FilePath.txt

      0