#include #include #include #include #include #include #include #include using hclock = std::chrono::high_resolution_clock; using duration = std::chrono::duration; int execmd(char* cmd,char* result) { char buffer[512]; FILE* pipe = _popen(cmd, "r"); if (!pipe) return 0; while(!feof(pipe)) { if(fgets(buffer, 128, pipe)){ strcat(result,buffer); } } _pclose(pipe); return 0; } std::string GetCommandOutput(std::string command) { std::string result(""); char buffer[1024]; FILE* pipe = _popen(command.c_str(), "r"); if (!pipe) return 0; while (!feof(pipe)) { if (fgets(buffer, 1024, pipe)) { result += buffer; } } return result; } std::vector split(std::string& str, std::string delemeter) { std::vector strs; size_t delsize = delemeter.size(); while (str.size() > 0) { size_t delpos = str.find(delemeter); if (delpos == std::string::npos) { strs.push_back(str); } else { strs.push_back(str.substr(0, delpos)); str = str.substr(delpos + delsize); } } return strs; } struct ConsoleSize { size_t w = 0; size_t h = 0; }; ConsoleSize get_console_size(std::string& content) { std::vector strs = split(content, "\n"); ConsoleSize sz; sz.h = strs.size(); for (size_t i = 0; i < strs.size(); i++) { if (strs[i].size() > sz.w) { sz.w = strs[i].size(); } } return sz; } void Trimmedoutput(std::string& content, size_t max_w, size_t max_h) { std::vector strs = split(content, "\n"); size_t lines = max_h > strs.size()?strs.size():max_h; for (size_t i = 0; i < lines; i++) { std::string str = strs[i]; if (str.size() > max_w) { str = str.substr(0, max_w); } else if (str.size() < max_w) { str += std::string(max_w - str.size(), ' '); } std::cout<(t2 - t1).count(); double remeaning = interval - elasped; if (remeaning > 0) { Sleep(int(remeaning * 1000)); } } return 0; }