调整目录

This commit is contained in:
2023-10-09 20:38:38 +08:00
parent 92cf854403
commit de8a41fff1
229 changed files with 54018 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
#include "CmdUtil.h"
#include <stdafx.h>
#include <iostream>
#include <Windows.h>
#include <string>
#include "spdlog/spdlog.h"
using namespace std;
std::string CmdUtil::ExecuteCommand(const std::string& command)
{
spdlog::info("ExecuteCommand command:{0}", command);
auto cmd_result = std::string();
char psBuffer[0x2000] = { 0 };
FILE* pPipe;
/* Run DIR so that it writes its output to a pipe. Open this
* pipe with read text attribute so that we can read it
* like a text file.
*/
if ((pPipe = _popen(command.c_str(), "rt")) == NULL)
{
exit(1);
}
/* Read pipe until end of file, or an error occurs. */
while (fgets(psBuffer, 0x2000, pPipe))
{
cmd_result += psBuffer;
memset(psBuffer, 0, 0x2000);
}
int endOfFileVal = feof(pPipe);
int closeReturnVal = _pclose(pPipe);
if (endOfFileVal)
{
spdlog::info("ExecuteCommand, Process returned {0}", closeReturnVal);
}
else
{
spdlog::error("ExecuteCommand Error: Failed to read the pipe to the end");
}
spdlog::info("ExecuteCommand result: {0}", cmd_result);
return cmd_result;
}