c - exec() is not throwing an error, but not running the other executable. Syntax error? -
i'm trying use fork() , exec() run program resides in same directery. compiler not complaining, program trying call using execl() not being run. tips? thank you!
pid = fork(); if (pid == -1) { fprintf (stderr, "error\n"); exit(1); } else if (pid > 0) { wait(&status); } else { execl("./expo.c", "./expo", x, n, (char*) null); _exit(exit_failure); }
i have tried few different versions of exec() , none have worked.
edit: have changed execl("expo","expo",&x,&n,(char*)null); , though still unsure why works based on man pages. man page says first argument should path, not executable. also, why not need ./ second argument if need run executable in terminal?
i have got working correctly, here changed. instead of casting arguments (x , n) ints passing them child, passed them chars , casted them ints in child process.
if(pid==-1){ fprintf (stderr, "error\n"); exit(1); } else if(pid>0){ wait(&status); } else{ const char *x=argv[1]; const char *n=argv[2]; execl("expo","expo",x,n,(char*)null); perror("execl() failure!\n"); exit(exit_failure); }
Comments
Post a Comment