Linux C system函数返回值

发布于 2020-07-02  90 次阅读


pid_t status = system("./test.sh");

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: %d\n", WEXITSTATUS(status));
		}
	}
	else
	{
		printf("exit status = [%d]\n", WEXITSTATUS(status));  
	}
}