This is the mail archive of the guile@cygnus.com mailing list for the guile project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Hi, I tried to run a coprocess via fork, but something prevents display from writing the data to the pipe. I used this code: (let ((fd1 (pipe)) (fd2 (pipe))) (let ((pid (primitive-fork))) (cond ((> pid 0) ; parent (close (car fd1)) (close (cdr fd2)) ; write two numbers (display "5 7\n" (cdr fd1)) ; read result (display "read from add2: ") (write (read-line (car fd2))) (display "here am I\n") (newline)) ((= pid 0) ; child (close (cdr fd1)) (close (car fd2)) ; define stdin and stdout (dup->inport (car fd1) (port->fdes (current-input-port))) (dup->outport (cdr fd2) (port->fdes (current-output-port))) (execl "./add2" "add2"))))) The point "here am I" is never reached. The add2 programm should reads a line via read (no buffering) and returns the sum, but it does not get any input. The simple add2: /* example from Stevens: program 14.8 */ #include <unistd.h> #include <string.h> #include "warn.h" #define MAXLINE 100 int main (int argc, char *argv[]) { int n, int1, int2; char line[MAXLINE]; int i; while ((n = read (STDIN_FILENO, line, MAXLINE)) > 0) { line[n] = 0; WARN ("here am I in add2"); if (sscanf (line, "%d%d", &int1, &int2) == 2) { sprintf (line, "%d\n", int1 + int2); n = strlen (line); /* for (i=0; i<5; i++) */ if (write (STDOUT_FILENO, line, n) != n) WARN ("write error"); } else if (write (STDOUT_FILENO, "invalid args\n", 13) != 13) WARN ("write error"); } return 0; } When I use add2 with a C programm it works fine: $ ./call-add2 *** main in add2.c[19]: here am I in add2 12 But with the Guile fork add2 does not read anything. Does anybody know why this does not work or can anybody send me an example, how to do this in Guile? -- http://www.ping.de/sites/aibon/