每日总结
20240228
1.获取系统命令执行结果
#include <stdio.h>#define TRUE 1
#define FALSE 0int 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[])
{char buffer[1024];if (get_system_cmd_result("md5sum main.cpp", buffer, 1024) == TRUE) {printf("ls result: %s\n", buffer);}return 0;
}