赞
踩
#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; }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。