dsg@MBUNIX.B.MITRE.ORG (Dave Goldberg) (08/16/88)
I don't know if this is a C or Unix question, so I apologize if this isn't
the appropriate group. Anyway:
We're implementing a distributed printing facility using ethernet connected
Imagen printers. In order to allow us to have local burst pages, I wrote a
small program to build and send a banner page, and then send the job. The
strangeness is that even though the sequence of the program indicated that
the banner page should be printed first, it was coming out after the job.
Here's a bit of the code:
char *banner, c;
FILE *fb,*pg;
banner = buildbanner(); /*
* buildbanner builds a temp file with the
* postscript in it and returns the file's path
*/
if ((fb = fopen(banner,"r")) != NULL) {
while ((c = getc(fb)) != EOF)
putchar(c);
fclose(fb);
unlink(banner);
}
pg = popen("/usr/local/lib/ps/pstext","w"); /* No flames, in the real
I check for errors */
while ((c = getchar()) != EOF)
putc(c,pg);
pclose(pg);
Now it seems to me that the banner page should be printed first, but it
isn't. To fix the problem, I fork(2)ed a process to print the banner page and
wait(2) for it before sending the rest of the job. This now works as I'd
expect. But the question remains: why do I have to?
Please email responses as I don't want to clutter the net, especially if
it's a real simple thing I've missed in the manual. If there's any interest
I'll summarize.
Thanks much,
-dave
--------------------------------------------------------------------------
Dave Goldberg ARPA: dsg@mitre-bedford.arpa
The Mitre Corporation UUCP: linus!mbunix!dsg
MS B015
Bedford, MA 01730
617-271-2460