Menu

Print to Windows Printer?

Tom Lake
2023-05-28
2023-06-03
  • Tom Lake

    Tom Lake - 2023-05-28

    Is there any way to use the system printer in Windows?

     
  • Simon Sobisch

    Simon Sobisch - 2023-05-28

    I guess (hope) you have used the search function?

    Please reference topics you've checked out, in this case [a547cb1c9] has the note that direct printing works fine as long as you have the printer on a "real" serial/parallel port assigning its name to the print file.

    At the end it also has a sample program to use this along with escape sequences (printer/vendor specific) to get formatted output.

    Likely you've also stumbled over [f4a2b09b9] and [410058ab9] (the later also mentioning to send a file to the system spooler using CALL 'SYSTEM' USING 'notepad /p name' and [a1bd7de9ac9] which shows a way to create a formatted rich-text file (which you then can again send to default spooler with libreoffice (wordpad would likely work similar) or others - that option would also allow you to create PDFs from that.

    ... those are all on the first page from the search results.

    As this topic is now created, please drop a note what helped you most, if it is "directly" related to one of those topics, then best there, otherwise possibly here.

     
  • Tom Lake

    Tom Lake - 2023-05-31

    I've tried them but nothing seems to work on my system. I can share the printer and use

    NET USE LPT1 \\home-pc\sysprint /persistent:yes
    

    to assign the share to device LPT1: but neither MSYS2 nor OpenCOBOL respects either the mapping or the share.

               SELECT PRINT-FILE  ASSIGN TO 'LPT1:'
               ORGANIZATION LINE SEQUENTIAL.
    
               libcob: error: file sharing conflict (status = 61) for file PRINT-FILE ('LPT1:')
    
               SELECT PRINT-FILE  ASSIGN TO '\\tom-home-pc\sysprint'
               ORGANIZATION LINE SEQUENTIAL.
    
           libcob: error: permanent file error (status = 30) for file PRINT-FILE ('\\home-pc\sysprint' => \home-pc\sysprint)    
    

    Since the printer is on USB001, I also tried this:

               SELECT PRINT-FILE  ASSIGN TO 'USB001'
               ORGANIZATION LINE SEQUENTIAL.
    

    I get no runtime error but the output is sent to a file named USB001 and not the port.

     
    • Simon Sobisch

      Simon Sobisch - 2023-05-31

      I've never tried that but seen a reference that under mingw/msys use of UNC paths may need forward slashes - ASSIGN TO '//tom-home-pc/sysprint' (no idea if this works, but you may want to try).

      Also open to try after NET USE LPT1: SELECT PRINT-FILE ASSIGN TO 'LPT1' - this seems to have worked in [028ac1dac6].

       

      Related

      Discussion: 028ac1dac6


      Last edit: Simon Sobisch 2023-05-31
    • Vincent (Bryan) Coen

      From your comments I have to "assume" you are running Windows but for
      Linux the normal processing is to install CUPS.
      I do not know if that is available under Windows.

      So, with that in mind you could try using the print spool name you have
      set up and here
      in my case it is Smart_Tank_7300

      Using that set it in the ASSIGN so in your case its:

      |SELECTPRINT-FILEASSIGNTO"|Smart_Tank_7300"

      Recompile the program and try it.

      I do not work with Windows with Cobol so cannot try it for you.

      Personally I use in the assign "lpt-1" and at the EOJ issue
      call "SYSTEM" using Print-Report.

      Where Print-Report is :
      >
       01  Print-Report.
           03  filler          pic x(117)     value
           "lpr -r -o 'orientation-requested=4 page-left=21 page-top=48 " &
           "page-right=10 sides=two-sided-long-edge cpi=12 lpi=8' -P ".
           03  PSN             pic x(48)      value "Smart_Tank_7300 ". 
      >
      This is the Cups print spool, change it for yours
           03  PP-Name         pic x(24)      value "prt-1". > Don't change
      this line 18/02/23 was X(15)
      >
       01  PP-Print-File-Name  pic x(24)      value "prt-1".

      The system this is taken from has up to 4 printers in the system named
      in Cobol as rpt-1, 2, 3 & 4 and they are in different locations.
      Also printer spool all refer to network printers.

      I seem to recall that this can be used in windows subject to how or what
      you use to set up printer spools.

      On 31/05/2023 14:24, Tom Lake wrote:

      I've tried them but nothing seems to work on my system. I can share
      the printer and use

      |NET USE LPT1 \home-pc\sysprint /persistent:yes |

      to assign the share to device LPT1: but neither MSYS2 nor OpenCOBOL
      respects either the mapping or the share.

      |SELECTPRINT-FILEASSIGNTO'LPT1:' ORGANIZATIONLINESEQUENTIAL.
      libcob:error:filesharingconflict(status=61)forfilePRINT-FILE('LPT1:') |
      |SELECTPRINT-FILEASSIGNTO'\tom-home-pc\sysprint'
      ORGANIZATIONLINESEQUENTIAL.
      libcob:error:permanentfileerror(status=30)forfilePRINT-FILE('\home-pc\sysprint'=>\home-pc\sysprint)|

      Since the printer is on USB001, I also tried this:

      |SELECT PRINT-FILE ASSIGN TO 'USB001' ORGANIZATION LINE SEQUENTIAL. |

      I get no runtime error but the output is sent to a file named USB001
      and not the port.

       
  • Tom Lake

    Tom Lake - 2023-06-03

    I finally settled for adding these lines (SYSPRINT is the output file):

               CALL "SYSTEM" USING "START WINWORD SYSPRINT "
               & "/mFilePrintDefault /mFileClose /mFileExit /q /n".
    
     

Anonymous
Anonymous

Add attachments
Cancel