I want to compile a source C in a parent process and then , the executable created , I want to run it into a son process. Any ideas?
Thank you.
#include <stdio.h>
#include <stdlib.h>
#define execle("/bin/ls","bin/ls","-l",NULL);
int main(int argc , char **argv )
{
int i;
for(i=1 ; i<argc ; i++)
{
if(argv[1]==".c")
{
if(fork()==0)
{
execle("/usr/bin/gcc","/usr/bin/gcc",argv[1],NULL);
exit(1);
}
}
if(argv[2]==".out")
{
if(fork()==0)
{
execle("/bin/cat","bin/cat/",argv[2],NULL);
exit(1);
}
}
}
return 0;
}
Here is how the code looks like , but can you tell me why it gives me errors on the lines where execle(..) is ?
In your parent/driver program, use the
system(3)call or a combination offork/exec/waitto run your compiler. Then you can use the same calls to run the newly compiled executable.Keep in mind the security aspects of this while implementing it. This kind of thing has a huge exploit potential.