# 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).
The
following example is one way I tried it, but the callback
pipe_cb seems to
be invoked repeatedly with the last line
that was output from the external
process even though the
pipe is at end of file. Is that the correct
behavior?
Is there something wrong or is there another better way
of
accomplishing this task?
Xforms: v0.89
OS: Dec Unix
4.0d
/*-----------------------*/
#include <stdio.h>
#include
<stdlib.h>
#include "forms.h"
FILE *fp;
void pipe_cb(int fd, void
*data)
{
static char str[256];
static i = 0;
fgets(str, 256,
fp);
if (feof(fp))
printf("eof ");
/* this line would be
output to browser */
printf("%s %d\n", str, i++);fflush(stdout);
if
(i > 10)
exit(-1);
}
int main(int argc, char *argv[])
{
FL_FORM
*simpleform;
int fd;
fl_initialize(&argc, argv, "Pipe Form", 0,
0);
simpleform = fl_bgn_form(FL_UP_BOX,230,160);
fl_end_form();
if ((fp = popen("echo Hello", "r")) == NULL)
{
printf("Error
opening pipe\n");
exit(-1);
}
fd = fileno(fp);
fl_add_io_callback(fd, FL_READ, (FL_IO_CALLBACK)pipe_cb, NULL);
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 - 10:56:59 EDT