2024年1月15日发(作者:)

#include

#include

#include

#include

int main()

{

pid_t status;

status = system("./");

if (-1 == status)

{

printf("system error!");

}

else

{

printf("exit status value = [0x%x]n", status);

if (WIFEXITED(status))

{

if (0 == WEXITSTATUS(status))

{

printf("run shell script successfully.n");

}

else

{

printf("run shell script fail, script exit code: %dn", WEXITSTATUS(status));

}

}

else

{

printf("exit status = [%d]n", WEXITSTATUS(status));

}

}

return 0;

}

WIFEXITED(stat_val) Evaluates to a non-zero value if statuswas returned for a child process thatterminated TATUS(stat_val) If the value of WIFEXITED(stat_val) isnon-zero, this macro evaluates to thelow-order 8 bits of the status argumentthat the child process passed to _exit()or exit(), or the value the childprocess returned from main().