home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / unix / programm / 6054 < prev    next >
Encoding:
Text File  |  1993-01-27  |  1.5 KB  |  56 lines

  1. Newsgroups: comp.unix.programmer
  2. Path: sparky!uunet!comp.vuw.ac.nz!lundman
  3. From: lundman@kauri.vuw.ac.nz (L Lundman)
  4. Subject: More advanced popen()
  5. Nntp-Posting-Host: kauri.vuw.ac.nz
  6. Message-ID: <LUNDMAN.93Jan27223935@kauri.kauri.vuw.ac.nz>
  7. Organization: Disorganised.
  8. Sender: news@comp.vuw.ac.nz (News Admin)
  9. Date: Wed, 27 Jan 1993 10:39:35 GMT
  10. Distribution: comp
  11. Lines: 43
  12.  
  13.  
  14. After finding out that popen() only read or wrote to a process and not both
  15. I was told I had to write one of my own if I wanted one. Can someone
  16. inform me why this code doesn't seem to work?
  17.  
  18. (Knowing my luck, it's some dumb mistake ;) )
  19.  
  20.  
  21. int 
  22.   mypopen(int *read, int *write, char *path)
  23. {
  24.  
  25.   /* First check to see if path is executable... */
  26.   int childfd[2];
  27.   int childpid;
  28.  
  29.  
  30.   if (pipe(childfd)) return -1;
  31.  
  32.   childpid = fork();
  33.   if (!childpid) {
  34.     /* this is the child */
  35.  
  36.     dup2(childfd[0] , 0);
  37.     dup2(childfd[1], 1);
  38.     execl(path,path,NULL,NULL);
  39.     
  40.     exit(0); /* Not needed ? */
  41.   }
  42.   else {
  43.     *read = childfd[0];
  44.     *write = childfd[1];
  45.     return childpid;
  46.   }
  47. }
  48.  
  49. --
  50. -------------------------------------------------------------------------------
  51. Jorgen Lundman         eMail: lundman@kauri.vuw.ac.nz, lundman@rata.vuw.ac.nz.
  52. 8 Atua Street          My thoughts are my own and not VUW's..
  53. Johnsonville,wgtn      "Research indicate that only 21 percent of what goes
  54. New Zealand            wrong here is actually my fault."
  55. Phone: +64 4 478 2724 (GMT+11 hrs) Amiga Archive Admin on ftphost.vuw.ac.nz
  56.