Re: XForms: Plumbing

From: Clive A Stubbings (xforms@vjet.demon.co.uk)
Date: Fri Jun 16 2000 - 18:00:07 EDT

  • Next message: Paolo Prandini: "R: R: R: R: XForms: More on the subject of threads"

    # To subscribers of the xforms list from Clive A Stubbings <xforms@vjet.demon.co.uk> :

    rob.carpenter@lmco.com wrote....

    > # To subscribers of the xforms list from rob.carpenter@lmco.com :
    >
    > I am trying to connect a pipe to an external process and
    >
    > print the stdout and stderr of the process to my own browser
    > (not the Command Log).
    >

    Rob..

    Try the following "additions"

    #include <stdio.h>
    #include <stdlib.h>
    #include "forms.h"

    void pipe_cb(int fd, void
    *data)
    {
            static char str[256];
            static i = 0;
            FILE *fp;

            fp = (FILE *) data;

            if (fgets(str, 256, fp)) {

                    /* this line would be output to browser */
                    printf("%s %d\n", str, i++);fflush(stdout);

                    if (i > 10)
                            exit(-1);
            } else if (feof(fp)) {
                    printf("eof\n");fflush(stdout);
                    fl_remove_io_callback(fileno(fp), FL_READ, (FL_IO_CALLBACK)pipe_cb);
                    pclose(fp);
            }
    }

    int main(int argc, char *argv[])
    {
            FILE *fp;
            int fd;
            FL_FORM *simpleform;

            fl_initialize(&argc, argv, "Pipe Form", 0, 0);
            simpleform = fl_bgn_form(FL_UP_BOX,230,160);
            fl_end_form();

            if ((fp = popen("head --lines=3 misc.c", "r")) == NULL) {
                    printf("Error opening pipe\n");
                    exit(-1);
            }
            fd = fileno(fp);

            fl_add_io_callback(fd, FL_READ, (FL_IO_CALLBACK)pipe_cb, (void *)fp);

            fl_show_form(simpleform, FL_PLACE_MOUSE, FL_NOBORDER, "Pipe Test");

            fl_do_forms();
    }
    _________________________________________________
    To unsubscribe, send the message "unsubscribe" to
    xforms-request@bob.usuhs.mil or see
    http://bob.usuhs.mil/mailserv/xforms.html
    XForms Home Page: http://world.std.com/~xforms
    List Archive: http://bob.usuhs.mil/mailserv/list-archives/



    This archive was generated by hypermail 2b29 : Fri Jun 16 2000 - 18:06:18 EDT