How to print from BASIC DOS to any Windows printerIntroduction
This article applies to the Basic programming language and its DOS variations (GWBasic, QuickBasic, PowerBasic, etc.) covering different topics about how to correctly manage Windows printing:
DOS Basic programs are used to print by using LPRINT statements, which directly send the specified characters to the LPT1: (only) parallel port.
In the age of DOS, typically a dot-matrix printer was connected to LPT1:, starting printing that data as soon as it was sent to the port and before all the data has been sent by the program, but on recent Windows systems this causes a common problem: The DOS print job starts after a long time or only when closing the Basic program. That's because LPRINT does not close the printer port at the print job end.
Fortunately, the Basic language already provides a solution for this problem. Consider this source:
10 LPRINT "Hello world"
You can obtain the same behaviour changing it as:
10 OPEN "LPT1:" FOR OUTPUT AS #1
20 PRINT #1,"Hello world"
30 CLOSE #1
with two main advantages:
So far you've solved one of your problems, but you still need a DOS compatible printer connected to the port specified in line 10.
Basic cannot directly address USB, DOT4 and other Windows ports which were not available in the age of DOS, so you cannot insert them in Line 10. In addition, more and more printers nowadays are GDI (also known as Windows-Only or host-based printers), which cannot be driven by a DOS program neither if they are connected to LPT1: or if you forward the LPT1: output to one of the ports above with a simple redirection utility like the NET USE Windows command.
These aspects are covered in detail in the article: How to print from DOS to USB Windows-Only printers.
So, you need a Windows program like Printfil to capture the Basic (DOS) print job, convert it into a GDI (Windows) job, THEN forward it to one of the above printers.
Printfil can be configured to capture the LPT output itself, but as a programmer you may want to change the sample source above as follows:
20 REM D$="LPT1:"
30 OPEN D$ FOR OUTPUT AS #1
40 PRINT #1,"Hello world"
50 CLOSE #1
Depending by whether line 20 is commented (REM) or not, you can make your Basic program printing directly to the LPT1 port (just like LPRINT) or to a file on disk. Now you just have to insert "c:\basic\printfil.txt" in the "File to check" field of the Printfil's configuration dialog to have Printfil automatically capturing your Basic print jobs and forwarding them to any printer installed in your Windows Control Panel (including USB, GDI, DOT4 and virtual printers), without having to configure it to capture the LPT1: output.