每日总结 20240228 1.获取系统命令执行结果 #include <stdio.h> #define TRUE 1 #define FALSE 0 int get_system_cmd_result(const char *command, char *buffer, int bufferLen) { FILE *pipe = popen(command, "r"); if (pipe == NULL) { return FALSE; } while (fgets(buffer, bufferLen, pipe) != NULL) { // 循环读取命令执行结果 } int returnValue = pclose(pipe); if (returnValue == -1) { return FALSE; } return TRUE; } int main(int argc, char const *argv[]) { /* code */ char buffer[1024]; if (get_system_cmd_result("md5sum main.cpp", buffer, 1024) == TRUE) { printf("ls result: %s\n", buffer); } return 0; }