Interfacing C Code to Shell Script
Kartik Subbarao
subbarao at phoenix.Princeton.EDU
Thu May 31 04:06:37 AEST 1990
In article <23487 at adm.BRL.MIL> rose at 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 at silvertone.Princeton.EDU (NeXT mail) -|
subbarao at pucc.Princeton.EDU - Bitnet
More information about the Comp.unix.questions
mailing list