1 bool OnShellCall(const char *shell_cmd, CString& result) 2 { 3 FILE* pipe = ::popen(shell_cmd, "r"); 4 if (!pipe) 5 { 6 return false; 7 } 8 9 char b ...
1 bool OnShellCall(const char *shell_cmd, CString& result) 2 { 3 FILE* pipe = ::popen(shell_cmd, "r"); 4 if (!pipe) 5 { 6 return false; 7 } 8 9 char buffer[256] = {0}; 10 result = ""; 11 char * s_read = NULL; 12 while(!feof(pipe)) 13 { 14 //s_read return null 或讀取完畢 15 s_read = fgets(buffer, sizeof(buffer), pipe); 16 if (NULL!=s_read) 17 { 18 result += buffer; 19 20 } 21 else 22 { 23 break; 24 } 25 } 26 27 pclose(pipe); 28 s_read = NULL; 29 return TRUE; 30 }獲取shell腳本/命令 執行的結果