system函数详解
加强版system函数
//判断linux运行命令是否OK
bool checkShellCm(const char *cmd)
{
// status = 0 && result = 0 is good other bad
int status;
int result;
result = system(cmd);
//printf("result=%d\n", result);
if (-1 == result)
{
perror("system()");
}
else if (WIFEXITED(result))
{
status = WEXITSTATUS(result);
//printf("status=%d\n", status);
if (127 == status)
{
printf("%s\n",
"Some error prevents the command language "
"interpreter from executing after the child "
"process is created,");
}
else if (126 == status)
{
printf("%s\n", "cannot execute");
}
else
{
/*printf("%s %d\n",
"Command terminationed with status", status); */
}
}
bool ifOK = (status || result);
return ifOK;
}