ITEM: BD2294L

How can I get print queue status from a C program?



Question:

c program with system call to lpstat - how can he do it faster?

Response:

ENV:
        AIX 3.2.5
        Various models
DESC:
        I am writing some code and need to present to the user a list
        of all the print queues which are in a READY status.  I am
        currently just doing a system("lpstat"); but this is pretty
        slow, especially if there is a problem with any remote queues.
        Is there a better way to get the status of a print queue in a
        C program?
ACT:
        
Response:

\#include \
\#include \
\#include \
\#include \
\#include \

int main()
{       DIR             *dp;            /* The directory we want look at */
        struct  dirent  *dirp;          /* A directory entry (file)      */
        char    filename[80];

        /* Open the directory with the print queue status files */
        if ((dp = opendir("/var/spool/lpd/stat")) == NULL)
            exit(1);

        /* One at a time get the names of files in the status directory */
        while ((dirp = readdir(dp)) != NULL)
                /* If this file name begins with s. then it's a status file */
                if(!strncmp("s.", dirp->d_name, 2)) 
                {
                   sprintf(filename, "/var/spool/lpd/stat/");
                   strcat(filename, dirp->d_name);
                   getstatus(filename);
                }
}int getstatus(filename)
char *filename;
{       /* File that has status for this print queue */
        FILE *status_file;

        /* All info about a print queue status is in a stfile struct */
        struct stfile status;

        status_file = fopen(filename, "r");
        /* Read sizeof(struct stfile) bytes from stat file into status */
        read(fileno(status_file), (char *)&status, sizeof(struct stfile));

        /* Queue status is found in byte 3 of the stfile structure
           This will be 1 for an enabled queue, 4 for a disabled
           or DOWN queue as defined in /usr/include/IN/backend.h
        */

        printf("Print queue %s has status ", filename);
        switch (status.s_status)
        {
           case READY:          printf("READY\\n");
                                break;

           case RUNNING:        printf("RUNNING\\n");
                                break;
                   case WAITING:        printf("WAITING\\n");
                                break;

           case OFF:            printf("DOWN\\n");
                                break;

           default:             printf("UNKNOWN\\n");
                                break;
        }
}
Response:

Closing with Customer Approval


Support Line: How can I get print queue status from a C program? ITEM: BD2294L
Dated: December 1995 Category: N/A
This HTML file was generated 99/06/24~13:30:23
Comments or suggestions? Contact us