点击(此处)折叠或打开

  1. int executeCMD(const char *cmd,char *result)
  2. {
  3.     char buf_ps[512];
  4.     char ps[512]={0};
  5.     int len=0;
  6.     FILE *ptr;
  7.     strcpy(ps, cmd);
  8.     if((ptr=popen(ps, "r"))!=NULL)
  9.     {
  10.         while(fgets(buf_ps, 512, ptr)!=NULL)
  11.         {
  12.            strcat(result, buf_ps);
  13.            if(strlen(result)>512)
  14.                break;
  15.         }
  16.         pclose(ptr);
  17.         ptr = NULL;
  18.     }
  19.     else
  20.     {
  21.         printf("popen %s error\n", ps);
  22.     }
  23. }

09-04 19:03
查看更多