diff --git a/src/netxs/desktopio/system.hpp b/src/netxs/desktopio/system.hpp index 2a432a31f..0dc9efe62 100644 --- a/src/netxs/desktopio/system.hpp +++ b/src/netxs/desktopio/system.hpp @@ -3377,7 +3377,7 @@ namespace netxs::os } return winsz; } - auto initialize() + auto initialize(bool trygui = faux) { #if defined(_WIN32) os::stdin_fd = fd_t{ ptr::test(::GetStdHandle(STD_INPUT_HANDLE ), os::invalid_fd) }; @@ -3488,18 +3488,20 @@ namespace netxs::os } else { - ok(::FreeConsole(), "::FreeConsole()", os::unexpected); - if (::AttachConsole(ATTACH_PARENT_PROCESS)) + if (trygui) { - os::stdin_fd = fd_t{ ptr::test(::GetStdHandle(STD_INPUT_HANDLE ), os::invalid_fd) }; - os::stdout_fd = fd_t{ ptr::test(::GetStdHandle(STD_OUTPUT_HANDLE), os::invalid_fd) }; - os::stderr_fd = fd_t{ ptr::test(::GetStdHandle(STD_ERROR_HANDLE ), os::invalid_fd) }; - } - else - { - // Run gui console. - ::MessageBoxW(NULL, L"Run GUI-console.", L"Run GUI-console.", MB_OK); - os::process::exit(0); + if (::FreeConsole() && ::AttachConsole(ATTACH_PARENT_PROCESS)) // We are hosted by shell. + { + os::stdin_fd = fd_t{ ptr::test(::GetStdHandle(STD_INPUT_HANDLE ), os::invalid_fd) }; + os::stdout_fd = fd_t{ ptr::test(::GetStdHandle(STD_OUTPUT_HANDLE), os::invalid_fd) }; + os::stderr_fd = fd_t{ ptr::test(::GetStdHandle(STD_ERROR_HANDLE ), os::invalid_fd) }; + } + else + { + // Run gui console. + ::MessageBoxW(NULL, L"Run GUI-console.", L"Run GUI-console.", MB_OK); + os::process::exit(0); + } } dtvt::win_sz = dtvt::consize(); diff --git a/src/vtm.cpp b/src/vtm.cpp index fca5911b4..3d8179f73 100644 --- a/src/vtm.cpp +++ b/src/vtm.cpp @@ -201,7 +201,8 @@ int main(int argc, char* argv[]) } } - os::dtvt::initialize(); + auto trygui = whoami == type::runapp || whoami == type::client; + os::dtvt::initialize(trygui); os::dtvt::checkpoint(); if (os::dtvt::vtmode & ui::console::redirio && (whoami == type::runapp || whoami == type::client))