C++.我想将更改后的特定字符行保存在字符串中

C++. I want to save a specific line of characters, that change, in a string

本文关键字:字符 保存 存在 字符串 C++      更新时间:2023-10-16

我通过C++应用程序在CMD中运行一个命令,该应用程序保存该命令的输出。在该输出中,有一个端口号和一个远程API令牌,每次重新启动应用程序im目标时,该令牌都会发生变化。

这是我通过CMD命令得到的输出,我将其存储在字符串中:

"C:/Riot Games/League of Legends/LeagueClientUx.exe" "--riotclient-auth-token=5NFOIOqKB9EfSVsxBMrFUw" "--riotclient-app-port=63498" "--no-rads" "--disable-self-update" "--region=EUW" "--locale=en_GB" "--remoting-auth-token=***vx5yZOk_TkAt9YKq-PEucw***" "--respawn-command=LeagueClient.exe" "--respawn-display-name=League of Legends" "--app-port=63530" "--install-directory=C:Riot GamesLeague of Legends" "--app-name=LeagueClient" "--ux-name=LeagueClientUx" "--ux-helper-name=LeagueClientUxHelper" "--log-dir=LeagueClient Logs" "--crash-reporting=crashpad" "--crash-environment=EUW1" "--crash-pipe=\.pipecrashpad_19692_AJMBMQYOZVYYJMRF" "--app-log-file-path=C:/Riot Games/League of Legends/Logs/LeagueClient Logs/2020-07-09T12-55-09_19692_LeagueClient.log" "--app-pid=19692" "--output-base-dir=C:Riot GamesLeague of Legends" "--no-proxy-server"

我已经尝试过使用regex库的一些东西,并设法将结果拆分为单词,但我仍然不知道如何保存特定的行,即端口号和远程验证authtoken="的结果;我要保存的字符";。

我的代码找出输出字符串中有多少单词:

std::string output = exec("wmic PROCESS WHERE name='LeagueClientUx.exe' GET commandline");
std::regex wregex("(\w+)");
auto words_begin = std::sregex_iterator(output.begin(), output.end(), wregex);
auto words_end = std::sregex_iterator();
std::cout << "Found: " << std::distance(words_begin, words_end) << std::endl;
PrintMatch(words_begin, words_end);

输出:

´´

找到:110 CommandLine,C,Riot,Games,League,of,Legends,LeagueClientUx,exe,riotclient,auth,token,5NFOIOqKB9EfSVsxBMrFUw,riotcclient,app,port,63498,no,rads,disable,self,update,region,EUW,locale,en_GB,remoting,auth,´´还有一点,但字符限制限制了我,但我需要存储的输出就在那里。我设置了逗号来标记输出中的新行。

''

这取决于你所说的"保存";。保存到文件还是只分配给变量?我的猜测是,您对迭代器的工作方式感到困惑,并想知道如何从words_begin变量中获取远程身份验证令牌和到的端口号。如果";单词";在cmd中,输出始终与您可以使用的相同:

std::advance(words_begin,16);
std::string port = words_begin->str();
std::advance(words_begin,13);
std::string authToken = words_begin->str();

现在,通常情况下,你会编写regex,以便只匹配你感兴趣的部分;单词";,这取决于远程身份验证令牌和端口号在cmd输出中的位置,如果该输出更改顺序或在前面添加另一个单词,则可能会导致应用程序中断。