Re: ESQL/C and printing
Posted in 1997
>From: Tim Kelly <Tkelly@svhs.org> >Date: Tue, 20 May 1997 12:28:52 -0400 >X-Informix-List-Id: <list.14585> > >I have an ESQL/C program that reads information out of an Informix database >and then writes it to a printer. The problem I'm currently having is how >do I access the Unix printers within C? Currently I'm using the /dev/..... >device files and that works fine. Only because you don't have two different people writing to the same printer device file at the same time! That's why printer spooling systems were invented at all. >But, we have now installed Axis >Communication ports and Intel Netports and the printers are installed on >the network. These printers are each installed into the LP Spooler and I >can print fine. The problem is that each printer port uses a proprietary >program to spool through and the dev/... device files are NOT there. > > What I what to do is put the available printers into a database and have >the user select one and then print. Is there a way to access the LP >Spooler within ESQL/C without using direct devices? Of course! #define _POSIX_C_SOURCE 2 #include <stdio.h> int exit_status; FILE *fp = popen("lp", "w"); fprintf(fp, "data to be written to printer\\n"); exit_status = pclose(fp); Interestingly, popen() is neither part of ANSI C (not very surprising) nor POSIX.1 (ISO/IEC 9945-1:1996), but it is part of POSIX.2, and so is strictly enabled by defining _POSIX_C_SOURCE as shown. It is traditionally available on Unix, so you may not need the POSIX define (but it shouldn't do any harm). Of course, the command string to the popen() call can be any string you need, such as the value chosen from the list selected from the database. Yours, Jonathan Leffler (johnl@informix.com) #include <disclaimer.h>