#include <stdio.h> #include <string.h> #include "cmd_exec.h" #include "comm.h" string ExecCmd(const string & cmd) { char store[kPipeMax], command[kCmdMax]; string result; StrToCharStar(cmd, command); FILE *pfp = popen(command, "r"); if (NULL == pfp) return result; memset(store, 0, kPipeMax); while (kPipeMax-1 == fread(store, sizeof(char), kPipeMax-1, pfp) && !feof(pfp)) { result += store; memset(store, 0, kPipeMax); } result += store; return result; }