add output file argument

This commit is contained in:
MihailRis 2026-04-05 22:41:28 +03:00
parent 936a5c8525
commit d06d566f65
3 changed files with 31 additions and 5 deletions

View file

@ -362,7 +362,7 @@ static int l_start_debug_instance(lua::State* L) {
args.emplace_back(io::resolve(std::string(projectPath)).string());
}
platform::new_engine_instance(std::move(args));
platform::new_engine_instance(std::move(args), "");
return lua::pushinteger(L, port);
}

View file

@ -215,7 +215,9 @@ std::filesystem::path platform::get_executable_path() {
#endif
}
void platform::new_engine_instance(const std::vector<std::string>& args) {
void platform::new_engine_instance(
const std::vector<std::string>& args, std::filesystem::path outputFile
) {
auto executable = get_executable_path();
#ifdef _WIN32
@ -250,6 +252,24 @@ void platform::new_engine_instance(const std::vector<std::string>& args) {
auto commandString = toWString(ss.str());
STARTUPINFOW si = { sizeof(si) };
if (!outputFile.empty()) {
si.dwFlags |= STARTF_USESTDHANDLES;
si.hStdOutput = CreateFileW(
toWString(outputFile.u8string()).data(),
GENERIC_WRITE,
FILE_SHARE_WRITE | FILE_SHARE_READ,
nullptr,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
nullptr
);
if (si.hStdOutput == INVALID_HANDLE_VALUE) {
throw std::runtime_error(
"CreateFileW failed with code: " +
std::to_string(GetLastError())
);
}
}
PROCESS_INFORMATION pi = { 0 };
DWORD flags = CREATE_NEW_PROCESS_GROUP | DETACHED_PROCESS;
// | CREATE_NO_WINDOW;
@ -280,7 +300,11 @@ void platform::new_engine_instance(const std::vector<std::string>& args) {
for (int i = 0; i < args.size(); i++) {
ss << " " << util::quote(args[i]);
}
ss << " >/dev/null &";
if (outputFile.empty()) {
ss << " >/dev/null &";
} else {
ss << " >" << util::quote(outputFile.u8string()) << " &";
}
auto command = ss.str();
logger.info() << command;
@ -302,4 +326,4 @@ bool platform::stdin_has_data() {
fds.events = POLLIN;
return poll(&fds, 1, 0) == 1;
#endif
}
}

View file

@ -18,7 +18,9 @@ namespace platform {
/// @brief Get current process running executable path
std::filesystem::path get_executable_path();
/// @brief Run a separate engine instance with specified arguments
void new_engine_instance(const std::vector<std::string>& args);
void new_engine_instance(
const std::vector<std::string>& args, std::filesystem::path outputFile
);
/// @brief Open URL in web browser
bool open_url(const std::string& url);
/// @brief Check if stdin has input