system函數對返回值的處理,涉及3個階段:shell
1 bool mySystem(const char *command) 2 { 3 int status; 4 status = system(command); 5 6 if (-1 == status) 7 { 8 printf("mySystem: system error!"); 9 return false; 10 } 11 else 12 { 13 if (WIFEXITED(status)) 14 { 15 if (0 == WEXITSTATUS(status)) 16 { 17 return true; 18 } 19 printf("mySystem: run shell script fail, script exit code: %d\n", WEXITSTATUS(status)); 20 return false; 21 } 22 printf("mySystem: exit status = [%d]\n", WEXITSTATUS(status)); 23 return false; 24 } 25 } 26