popen
BOOL runPopenCommand(char *cmd)
{
BOOL ret = FALSE;
FILE *fp = popen(cmd, "r");
if(fp) {
char buf[256] = {0};
if(fgets(buf, sizeof(buf), fp) != NULL) {
ret = TRUE;
} else {
printf("Run popen \"%s\" failure\n", cmd);
}
if(pclose(fp) == -1) {
printf("Close popen \"%s\" failure\n", cmd);
}
} else {
printf("Run popen \"%s\" failure, system error\n", cmd);
}
return ret;
}
system
BOOL runSystemCommand(char *cmd)
{
BOOL ret = FALSE;
pid_t status = system(cmd);
if(status == -1) {
printf("System error");
} else {
if(WIFEXITED(status)) {
if(0 == WEXITSTATUS(status)) {
ret = TRUE;
} else {
printf("Run \"%s\" failed %d \n", cmd, WEXITSTATUS(status));
}
} else {
printf("Exit code %d \n", WEXITSTATUS(status));
}
}
return ret;
}