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.
source share