getLine(char *line, const char *cmd) {
  FILE *pf = popen(cmd, "r");
  if (pf == NULL) {
    return -1;
  }
  fgets(line, 25, pf);
  if (strlen(line) > 0) {
    if (line[strlen(line) - 1] == '\n')
      line[strlen(line) - 1] = '\0';
  }
  pclose(pf);
  return 0;
}

 

posted on 2019-02-20 11:26  Malphite  阅读(481)  评论(0编辑  收藏  举报