linux c 获取console 结果

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] == '
')
      line[strlen(line) - 1] = '';
  }
  pclose(pf);
  return 0;
}
原文地址:https://www.cnblogs.com/Malphite/p/10405509.html