Path: utzoo!attcan!uunet!aplcen!samsung!usc!elroy.jpl.nasa.gov!ames!haven!udel!princeton!phoenix!subbarao From: subbarao@phoenix.Princeton.EDU (Kartik Subbarao) Newsgroups: comp.unix.questions Subject: Re: Interfacing C Code to Shell Script Keywords: popen Message-ID: <16870@phoenix.Princeton.EDU> Date: 30 May 90 18:06:37 GMT References: <23487@adm.BRL.MIL> Reply-To: subbarao@phoenix.Princeton.EDU (Kartik Subbarao) Lines: 28 In article <23487@adm.BRL.MIL> rose@baby.swmed.utexas.edu (Rose Oguz) writes: > I want to call a shell script from my C program. However, I >would like the script to return values to my C program. Is there a Okay gang, even though many "official" unix.hackers out there might disagree, this one simply says that popen() is screaming for this job, just as it's supposed to :-). In your C shell script, do this: #!/bin/csh ... echo "(whatever the status you want to give to the c program)" then -- in your C program do this: FILE *cpipe = popen("name_of_cshell_script","r"); then just read from cpipe as if it were a file. e.g, c = getc(cpipe); fgets(foo, 500, cpipe); etc... -Kartik -- subbarao@{phoenix,bogey or gauguin}.Princeton.EDU -|Internet kartik@silvertone.Princeton.EDU (NeXT mail) -| subbarao@pucc.Princeton.EDU - Bitnet