how to call c executable inside c program??

hi guys
i have only basic knowledge of c so guys plz help me .....
i want 2 call c executable which requires file name as argument and i need to modify file contents before calling that executable now my question is how can i call this c executable inside another c program with arguments ??

i need this coz i can only call c program from cobol program and that c program should call this executable which requires file as argument in which i have to store my data and this data changes every time i call this c ....

Are you expecting to use the output of the executable file in the C program that calls it? If you do, then you'll need to use popen (read the man page for how to work with it). If not, then just use the exec family of functions (again the man page will tell you how to use them).

HI,
If you want to continue the execution of C prgram even after calling the executable from the C program, then try to use system() function call.
You can create a string with executable name and the arguments printed to the string using sprintf().
Then pass the string as argument to system() call.
If needed i can give you a example.
Raghu

thanx guys .......for your help i am working on it ........

hello please see the code snippet:-

#include<unistd.h>
int main()
{
const char* command ="./freenull";
execvp(command,NULL);
return 0;
}
/* in the same programme if u want u can create a child and can do the same inside that*/

or

#include<unistd.h>
int main()
{
const char* command="./freenull";
system("command");
return 1;
}

You need to see the manpage of the execl function.

thanks guys for replying but this thread is 2yrs old ....anyways i can still refer to this

#include <iostream>
#include <string>
using namespace std;

int main ()
{

    char cmd[50]=\{0x00\};
    sprintf\(cmd,"nohup ./%s &","exename"\);
    system\(cmd\);
    return 0;

}

You mean: system (command);
You probably want to return EXIT_SUCCESS (#include <stdlib.h>), not 1. The normal exit status for successful programs in unix is 0. Non-zero values are usually used to indicate some kind of failure.

Two years old thread? Let's add a subquestion, which makes the thread more complete: :smiley:

In shell and some scripting languages executables can be launched non-blocking using a "&" parameter.

The exec family of commands don't provide such a "background" launch, nor does the system() function provide this - according to my information.

The alternative (popen) would do, but upon pclose, it waits for actual termination of the piped process.

Any other way to do this?