lemoncube.com Search: (normal)
Articles
Links
News
Projects

Disclaimer

popen C code example

/*
    * Copyright (C) 1998, by Sun Microsystems, Inc.
    * All Rights Reserved
    */

    #pragma ident   "@(#)popen_printer_list.c       1.2     98/05/11 SMI"

    #include 
    #include 
    
    main(int ac, char *av[])
    {
            FILE *fp;
    
            if ((fp = popen("/usr/bin/lpstat -v", "r+")) != NULL) {
                char buf[BUFSIZ];
    
                while (fgets(buf, sizeof (buf), fp) != NULL) {
                    strtok(buf, ": ");      /* eat system/device */
                    strtok(NULL, ": ");     /* eat for */
                    printf("printer: %s\n", strtok(NULL, ": "));
                }
                fclose(fp);
                }
    }

pablo , 2003-09-05 21:25:20