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