This question already has an answer here:
I'm running execl function to compile a program through my code. And I want to check if the compilation went right. so I wrote
b = execl("usr/bin/gcc","cc",path,NULL); and later checked
if( b==-1). But even though there were errors in the compilations it didnt get into the if statement. Any ideas why? Thank you!
if ((pid1 = fork())<0)
Best How To :
exec succeeds it will NEVER return. Succeeding means be able to find and launch the command. If it doesn't succeed it will return -1.
What you need is to extract the exit value of the command from the
status used in the
wait in the parent process.
You have some macros to determine the status of the run of the child process.
WIFEXITED(status) will tell you if the command stopped by a call to
- and then you will be able to get the exit status with
status equals to 0 then you will know that the command run successfully, any other value means that the command wasn't able to do its task normally.