Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!wiley!wendar From: wendar@wiley.UUCP (Wendar Fu) Newsgroups: comp.windows.x Subject: XtAddInput question Message-ID: <9702@wiley.UUCP> Date: 2 May 90 22:13:08 GMT Organization: TRW Inc., Redondo Beach, CA Lines: 108 I'm a new x user, and I am having problem using XtAddInput(). I'm trying to write a program that forks a child process, and the parent process captures all the data that goes to standard output and standard error from the child process, and process them. The problem I have is it seems to enter an infinite loop, in which the handler routine is called repeatedly. The simplified program follows: ------------------------ char *btn_text; main(argc, argv) unsigned int argc; char **argv; { int n, i; int cpid, fd[2]; Widget toplevel, button; Arg args[10]; toplevel = XtInitialize("main", "XMdemos", NULL, NULL, &argc, argv); btn_text = XmStringCreateLtoR("Push to Quit", XmSTRING_DEFAULT_CHARSET); n = 0; XtSetArg(args[n], XmNlabelType, XmSTRING); n++; XtSetArg(args[n], XmNlabelString, btn_text); n++; button = XtCreateManagedWidget("button", xmPushButtonWidgetClass, toplevel, args, n); XtAddCallback(button, XmNactivateCallback, activateCB, NULL); fd[0] = fd[1] = -1; /* initialize file descriptors */ if(pipe(&fd[0]) != 0) { printf("main: pipe call failure\n"); exit(-1); } /* set all file descriptors execept stdin, stdout, stderr, and the */ /* that will be used by the new process for pipes, to be closed */ /* when the new process is forked */ for(i=3; i= 0) close(fd[i]); } exit(-1); default: /* parent process */ close(fd[1]); XtAddInput(fd[0], XtInputReadMask, handler, 0); break; } XtRealizeWidget(toplevel); XtMainLoop(); close(fd[0]); } void activateCB(w, client_data, call_data) Widget w; caddr_t client_data; caddr_t call_data; { XtFree(btn_text); exit(-1); } void handler() { /* read message from file descriptor and manages them */ } ------------------- The child process does nothing except for print a line to its standard error every couple of seconds. The handler routine is stilled called repeated when: (1) execl() is not called, (2) fd[0] and fd[1] are not closed. Please respond if you have see any error, or if you have a different approach to handle this. Thanks in advance! --- Wendar ---