System call return value in C

I use the system function in C code to invoke the cp command. I want to know if it was completed successfully or not?

+4
source share
2 answers

Use the system () function. It returns the status of the command being executed. If it is 0, then it looks like it will be successful.

+7
source

Should be enough to check the return value of the system call.

From man system on Mac:

The system () function returns the shell status returned by waitpid (2) or -1 if an error occurred while calling fork (2) or waitpid (2). A return value of 127 means shell execution failed.

+4
source

Source: https://habr.com/ru/post/1301312/


All Articles