mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41:51 +00:00
add output file argument
This commit is contained in:
parent
936a5c8525
commit
d06d566f65
3 changed files with 31 additions and 5 deletions
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue