Now grabbing output for subprocess. Only first lines for now

This commit is contained in:
Antoine Pilote
2024-08-14 20:51:40 -04:00
parent 1eb81041fb
commit 98f490e4e1
4 changed files with 1265 additions and 2 deletions

View File

@@ -2070,6 +2070,7 @@ namespace Nuake {
ImGui::TableSetupColumn("Message", ImGuiTableColumnFlags_WidthStretch, 1.0f);
ImGui::TableNextColumn();
ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, ImVec2(4, 4));
for (auto& l : Logger::GetLogs())
{
if (l.type == LOG_TYPE::VERBOSE && !LogDebug)
@@ -2560,7 +2561,6 @@ namespace Nuake {
SetStatusMessage(std::string(ICON_FA_EXCLAMATION_TRIANGLE) + " An unhandled exception occured in your script. See logs for more details.", Color(1.0f, 0.1f, 0.1f, 1.0f));
}
DrawStatusBar();
pInterface.DrawEntitySettings();

1217
Nuake/Subprocess.hpp Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -23,6 +23,7 @@
#include <chrono>
#include <imgui/imgui.h>
#include <Subprocess.hpp>
namespace Nuake {
@@ -141,12 +142,55 @@ namespace Nuake {
void OS::CompileSln(const std::string& slnPath)
{
int result = system(std::string("dotnet build " + slnPath).c_str());
std::string output = "";
std::string err = "";
int result = Subprocess("dotnet build " + slnPath, output, err);
if (result != 0)
{
Logger::Log("Failed to execute `dotnet build` command.", "OS", CRITICAL);
Logger::Log(err.c_str(), ".NET", LOG_TYPE::COMPILATION);
}
Logger::Log(output.c_str(), ".NET");
}
int OS::Subprocess(const std::string& command, std::string& out, std::string& err)
{
auto splits = String::Split(command, ' ');
std::vector<const char*> command_line(splits.size() + 1);
for (int i = 0; i < splits.size(); i++)
{
command_line[i] = splits[i].c_str();
}
command_line.back() = nullptr;
struct subprocess_s subprocess;
char output[1024];
int result = subprocess_create(command_line.data(), 0, &subprocess);
if (0 != result) {
// an error occurred!
}
int process_return;
result = subprocess_join(&subprocess, &process_return);
if (0 != result) {
// an error occurred!
}
FILE* p_stdout = subprocess_stdout(&subprocess);
fgets(output, 1024, p_stdout);
FILE* p_stderr = subprocess_stderr(&subprocess);
char errOutput[1024];
fgets(errOutput, 1024, p_stderr);
out = std::string(output);
err = std::string(errOutput);
return result;
}
void OS::OpenURL(const std::string& url)

View File

@@ -20,5 +20,7 @@ namespace Nuake
static void OpenURL(const std::string& url);
static std::string GetConfigFolderPath();
static void CompileSln(const std::string& slnPath);
static int Subprocess(const std::string& command, std::string& out, std::string& err);
};
}