You can use Windows devices by substituting a device name (such as PRN, LPT1, LPT2, COM1, and so on) for the file name when you create a stream object. Then use line or character methods to read or write the device.
The following example sends data to a printer (device name PRN in the example). In addition to sending text data, the example also sends a control character for starting a new page. You can send other control characters or escape sequences in a similar manner. (Generally, these are listed in the manual for the device.)
Usually the control characters are characters that you cannot type at the keyboard. To use them in your program, send a D2C message to the character's ASCII value as shown in the example.
/* PRINTIT.CMD - Prints a text file */ say "Type file name: " /* prompt for a file name */ pull filename /* ...and get it from the user */ infile=.stream~new(filename) printer=.stream~new("prn:") newpage = 12~d2c /* save page-eject character */ /* Repeat this loop until no lines remain in the file */ /* and keep track of the line count with COUNT */ do count = 1 until filename~lines = 0 if printer~lineout(infile~linein) <>0 then do say "Error: unable to write to printer" leave end if count // 50 = 0 then /* if the line count is a */ printer~charout(newpage) /* multiple of 50, then */ /* start a new page by */ /* sending the form feed */ end /* go back to the start of loop */ /* until no lines remain */ infile~close /* close the file */ exit /* end the program normally */