This will run a program and give me the return code.
int returnCode;
returnCode = system(program);
How can I do the same thing with execv?
The exec family of calls trash the current process and launch the new program within the same process space. If you want to execute another program within your current program, you need to spawn a new process using fork You then call exec in the child process and get the parent to wait until the child process completes. The waitpid function will then provide the child process's return code.
See here for an example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With