Invoke unix script using c program

hi

i want to invoke a unix script in a C program and also return some value from the script to the C program to use that value further.

Basically i am doing a Lookup operation in this unix script and returning the looked up data from a oracle database table..

please help me invoke as well as return dat from the script to C program.

A general answer -

  1. Preferred answer - develop Pro*C application that does what your sql script does

  2. use popen in read mode to execute a shell script; as the shell script generates text you can read the data from a file descriptor.

popen example:

char tmp [1024]={0x0};
FILE *in=popen("/path/to/myshellscript.sh", "r");
while fgets(tmp, sizeof(tmp), in)!=NULL)
{
        // tmp contains one line of data process with it here
}
pclose(in);