打赏

linux C获取system执行返回值

 注意,是获取执行的返回值,执行结果的返回值,一般成功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;
}

 

效果如下:

 

 

 

 

 

posted @ 2019-11-22 16:07  陈昌雄  阅读(3104)  评论(0编辑  收藏  举报