This commit is contained in:
parent
69b797c1aa
commit
8df52b4ae7
2 changed files with 45 additions and 11 deletions
|
|
@ -19,12 +19,16 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
|
||||
module;
|
||||
#include <stdio.h>
|
||||
#ifdef PLATFORM_WINDOWS
|
||||
#include <windows.h>
|
||||
#endif
|
||||
module Crafter.Build:Command_impl;
|
||||
import :Command;
|
||||
import std;
|
||||
|
||||
|
||||
namespace Crafter {
|
||||
#ifndef PLATFORM_WINDOWS
|
||||
std::string RunCommand(const std::string_view cmd) {
|
||||
std::array<char, 128> buffer;
|
||||
std::string result;
|
||||
|
|
@ -50,6 +54,36 @@ namespace Crafter {
|
|||
if (!pipe) throw std::runtime_error("popen() failed!");
|
||||
pclose(pipe);
|
||||
}
|
||||
#else
|
||||
std::string RunCommand(const std::string_view cmd) {
|
||||
std::array<char, 128> buffer;
|
||||
std::string result;
|
||||
std::string command = "cmd.exe /C " + std::string(cmd) + " 2>&1"; // Redirect stderr to stdout
|
||||
|
||||
// Open pipe to file
|
||||
FILE* pipe = _popen(command.c_str(), "r");
|
||||
if (!pipe) throw std::runtime_error("popen() failed!");
|
||||
|
||||
// Read till end of process:
|
||||
while (fgets(buffer.data(), buffer.size(), pipe) != nullptr) {
|
||||
result += buffer.data();
|
||||
}
|
||||
|
||||
// Close pipe
|
||||
_pclose(pipe);
|
||||
return result;
|
||||
}
|
||||
|
||||
void RunCommandIgnore(const std::string_view cmd) {
|
||||
std::string command = "cmd.exe /C " + std::string(cmd) + " > NUL 2>&1"; // Redirect stdout and stderr to NUL
|
||||
|
||||
// Open pipe to file
|
||||
FILE* pipe = _popen(command.c_str(), "r");
|
||||
if (!pipe) throw std::runtime_error("popen() failed!");
|
||||
_pclose(pipe);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// CompileException::CompileException(std::vector<CompileError>&& errors) : errors(std::move(errors)) {
|
||||
// for(CompileError error : errors) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue