Path: utzoo!utgpu!attcan!uunet!husc6!rutgers!caip.rutgers.edu!syeh From: syeh@caip.rutgers.edu (Simon Yeh) Newsgroups: comp.unix.wizards,ru.qa.network Subject: Re: How to do a pipe & fork? Message-ID: Date: 3 Nov 88 23:48:08 GMT References: Organization: Rutgers Univ., New Brunswick, N.J. Lines: 54 In article , pratt@zztop.rutgers.edu (Lorien Y. Pratt) writes: >OK, an even easier question than I posted last time, I'd really appreciate >your help. >Here's what I have so far, which I know is wrong. You may try this....[Note: lines starting with /*@*/ are what I added] #include #include #define STRLEN 40 main() { int pid; char from_sql[256]; char *fgets(); int i; /*@*/ int fd[2]; /* store file descriptors for pipe */ /*@*/ pipe(fd); /* creat pipe */ pid = fork(); if (pid == 0) /* We are the children */ { /*@*/ dup2(fd[1], 1); /* redirect child's stdout to fd[1] so child can talk to parent */ /*@*/ close(df[0]); close(fd[1]); /* This part works. I tested it in its own program without being a child. */ i = execlp("rsh", "rsh", "topaz", "/u2/ingres/bin/sql", "spam", 0); printf("execlp didn't work, return code is %d\n", i); /*@*/ exit(1); } else { printf( "Child's process ID is %d\n", pid ); fflush(stdout); /*@*/ close(fd[1]); /* Start talking to child */ /*@*/ fgets(from_sql, 256, fd[0] ); /* read what child says from fd[0] */ printf("SQL says: %s\n", from_sql ); /*@*/ fclose( fd[0] ); ...... } ..... } >Lorien Y. Pratt Computer Science Department >pratt@paul.rutgers.edu Rutgers University Hope this will help. --- Simon Yeh