Jump to page content

Hack Tales 1: e-mail printing

18th June 2003

I handle my dad’s e-mail at home, and it seems that the most convenient way to have him read them is by printing them out (it is better than having him call by invariably in the middle of an IM/IRC conversation and ruining it). Now, the e-mails all live on the Mac, which has no printer attached, so all the printing takes place on the 486 PC. Sparing you an account of how the files got to the PC, let’s now assume that, today, I have a lot of mails to print (a backlog) on a floppy disc sat in the PC, and I really don’t fancy printing them one at a time again.

Now, this is Windows 3.11 on the PC, which decided that it is too old to provide such useful functionality as being able to print a bunch of documents at once, and TextPad is not capable of doing that either, which is handy. So… the only way I can think of to automate this little process is a DOS for loop over all the .txt files on the floppy disc. However, it turned out to not be that simple.

Firstly, you need to iterate over all text files in the directory.

for %%l in (*.txt) do call prpg.bat %%l

Now, each file being printed needs to be followed by a page feed (ASCII 0x0C) character in order to make the printer eject the page. Otherwise, it runs all the files into each other. This means that printing each page is a two step process, and thus cannot be done directly inside a DOS batch loop. Hence, the loop calls a second batch file to handle each mail. That batch file looks like this:

type %1 > prn
d:\c\output\dopagefd.exe > prn

The first step outputs the contents of the specified file to the printer. The second step sends a page feed char to the printer. The best way to do this, I felt, was via a little C program, which I wrote thus:

#include <stdio.h>

void main (void) {
 printf("%c", 12);
 return;
}

And there we have it. Typing prall results in every e-mail ending up coming out the printer. Now, why couldn’t Microsoft have popped something similar into Windows 3.11 File Manager?