首页 > 代码库 > linux 程序调用system执行命令

linux 程序调用system执行命令

正确使用system方法,判断返回值

int exeCmd(const char *cmd) {        pid_t status;                status = system(cmd);            if (-1 == status)        {            WriteLog("system error!");        }        else        {            WriteLog("exit status value = http://www.mamicode.com/[0x%x]/n", status);                if (WIFEXITED(status))            {                if (0 == WEXITSTATUS(status))                {                    WriteLog("run CMD script successfully.\n");                    return 0;                }                else                {                    WriteLog("run CMD=[%s] script fail, script exit code: %d\n", cmd,WEXITSTATUS(status));                }            }            else            {                WriteLog("exit status = [%d]\n", WEXITSTATUS(status));            }        }            return -1;}

 

linux 程序调用system执行命令