my program writes a file (inside a function, using write and fread).And just after that i run
Code:
if(execute(2, tempFileName) ==ERR){ /* executes another program */
exit(1);
}
but in that case the program fails ... and says bad address.
But if i call execute from another program it runs perfectly.
I suspect that the function that writes the file is not completely correct.
Can anyone help me with this?
I posted this problem but no one seems to know...
http://cboard.cprogramming.com/showthread.php?t=98407
please help.
Code:
static char *program[8] = {
"./avgFilter",
"./binarize",
"./invert",
"", "", "", ""};
int execute(short progNumber, char * fileName){
int pid;
int status;
/*
* Get a child process
*/
if((pid = fork()) < 0){
perror("fork: ");
return(-1);
}
/*
* The child executes the program
*/
if(pid == 0){
execl(program[progNumber],program[progNumber], fileName, (char *)0);
perror("execl");
return(-1);
}
/*
* The parent process just waits
*/
if (pid >= 1) {
wait(&status);
}
return(0);
}