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

 

效果如下:

linux C获取system执行返回值

 

 

 

 

 

相关文章:

  • 2022-12-23
  • 2021-09-19
  • 2022-12-23
  • 2022-01-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-27
  • 2021-11-25
  • 2021-09-07
  • 2021-05-03
相关资源
相似解决方案