0

So I am trying to call a program from within a c file I am making but the only way I've been able to do that is by using the system() function which causes error on its own. To run the program in terminal I use;

~/odas/bin/odaslive -vc ~/odas/config/odaslive/matrix_creator.cfg

This is what I am currently trying to use to run that same program, it compiles and will run in terminal but nothing happens.

pid_t pid=fork();

if (pid==0){
    //static char *argv[] ={"echo","-vc ~/odas/config/odaslive/matrix_creator.cfg", NULL};
    execl("~/odas/bin", "~/odas/bin/odaslive", "-vc", "~/odas/config/odaslive/matrix_creator.cfg", (char *)NULL);
    exit(127);

} else {
    waitpid(pid,0,0);

}

1 Answers1

1

execl requires file path in the first argument.

It doesn't expand ~ with the home for path. The full path must be supplied.

Check a returned value and errno. It will inform you about a failure reason if any.

int ret = execl("/home/username/odas/bin/odaslive", "/home/username/odas/bin/odaslive", "-vc", "/home/username/odas/config/odaslive/matrix_creator.cfg", (char *)NULL);
273K
  • 29,503
  • 10
  • 41
  • 64