注意,是獲取執行的返回值,執行結果的返回值,一般成功0,失敗看情況
具體如下:
#include "stdio.h"
#include "unistd.h"
#include <stdlib.h>
#include <sys/wait.h>
#include <sys/types.h>
int main(int argc, char* argv[])
{
int ret = 0;
while(1)
{
ret = system("ls") ;
printf(WEXITSTATUS(ret)) ;
sleep(2) ;
}
return 0;
}
效果如下:

