home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.programmer
- Path: sparky!uunet!comp.vuw.ac.nz!lundman
- From: lundman@kauri.vuw.ac.nz (L Lundman)
- Subject: More advanced popen()
- Nntp-Posting-Host: kauri.vuw.ac.nz
- Message-ID: <LUNDMAN.93Jan27223935@kauri.kauri.vuw.ac.nz>
- Organization: Disorganised.
- Sender: news@comp.vuw.ac.nz (News Admin)
- Date: Wed, 27 Jan 1993 10:39:35 GMT
- Distribution: comp
- Lines: 43
-
-
- After finding out that popen() only read or wrote to a process and not both
- I was told I had to write one of my own if I wanted one. Can someone
- inform me why this code doesn't seem to work?
-
- (Knowing my luck, it's some dumb mistake ;) )
-
-
- int
- mypopen(int *read, int *write, char *path)
- {
-
- /* First check to see if path is executable... */
- int childfd[2];
- int childpid;
-
-
- if (pipe(childfd)) return -1;
-
- childpid = fork();
- if (!childpid) {
- /* this is the child */
-
- dup2(childfd[0] , 0);
- dup2(childfd[1], 1);
- execl(path,path,NULL,NULL);
-
- exit(0); /* Not needed ? */
- }
- else {
- *read = childfd[0];
- *write = childfd[1];
- return childpid;
- }
- }
-
- --
- -------------------------------------------------------------------------------
- Jorgen Lundman eMail: lundman@kauri.vuw.ac.nz, lundman@rata.vuw.ac.nz.
- 8 Atua Street My thoughts are my own and not VUW's..
- Johnsonville,wgtn "Research indicate that only 21 percent of what goes
- New Zealand wrong here is actually my fault."
- Phone: +64 4 478 2724 (GMT+11 hrs) Amiga Archive Admin on ftphost.vuw.ac.nz
-