#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
int
main(void)
{
int status;
int result;
result = system("./a021.sh");
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);
}
}
return 0;
}
C++ 中获取shell脚本返回值
最新推荐文章于 2024-02-01 09:22:01 发布