#include <iostream>
#include <cstdlib>
#include <string>
std::string exec(const char* cmd) {
char buffer[128];
std::string result = "";
FILE* pipe = _popen(cmd, "r");
if (!pipe) {
throw std::runtime_error("popen() failed!");
}
while (!feof(pipe)) {
if (fgets(buffer, 128, pipe) != nullptr) {
result += buffer;
}
}
_pclose(pipe);
return result;
}
std::string getSvnRevision() {
std::string cmd = "svn info --show-item revision";
std::string result = exec(cmd.c_str());
// 移除末尾的换行符
result.erase(result.find_last_not_of("\r\n") + 1);
return result;
}
int main() {
std::string svnRevision = getSvnRevision();
std::cout << "SVN 版本号: " << svnRevision << std::endl;
system("pause");
return 0;
}
用c++代码获取svn的版本号
最新推荐文章于 2024-05-13 06:53:03 发布