home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / unix / programm / 4303 < prev    next >
Encoding:
Internet Message Format  |  1992-08-14  |  1.6 KB

  1. Path: sparky!uunet!olivea!decwrl!sdd.hp.com!swrinde!gatech!destroyer!caen!umeecs!umn.edu!math.fu-berlin.de!unidui!flyer!easix!umunk!udo
  2. From: udo@umunk.GUN.de (Udo Munk)
  3. Newsgroups: comp.unix.programmer
  4. Subject: Re: Receiving output of Shell script into C program?
  5. Message-ID: <9208141288@umunk.GUN.de>
  6. Date: 14 Aug 92 20:01:59 GMT
  7. References: <bibhas.713556754@femto.engr.mun.ca>
  8. Organization: umunk (private)
  9. Lines: 21
  10. X-Newsreader: Tin 1.1 PL4
  11.  
  12. bibhas@pico.engr.mun.ca (Bibhas Bhattacharya) writes:
  13. : I am new to UNIX/C. I don't know if it's a FAQ, but, I couldn't find anyway
  14. : to communicate between shell scripts and C programs. It must be possible
  15. : through files (hopefully in UNIX every data target/source is a file?).
  16. : I'm not even thinking of ASCII files, which will work but would be
  17. : hopelessly impractical.
  18. : Any idea guys?
  19. : Bibhas.
  20.  
  21. Open a pipe with pipe() and reconnect stdin and stdout with dup2() to the
  22. pipe. Create a child process with fork() and exec() your shell script
  23. from the child process. Now everything what the parent process writes
  24. into the pipe goes to stdin of the shell script. Everything what the
  25. shell script writes to stdout can be readed by the parent process from
  26. the pipe.
  27. --
  28. Udo Munk     | voice:      +49 2131 275348             | uucp: +49 2131 278869
  29. Oberstr. 21  | mail :      udo@umunk.GUN.de            |     2400/1200/300 8N1
  30. 4040 Neuss 1 | ...!{mcshh,smurf,unido}!easix!umunk!udo | MYNAME=bbsuser
  31. Fed. Rep. of | CompuServe: 100021,2515                 | login: uucp
  32. Germany      | at first connect get ~/info  and ~/files| pwd:   public
  33.