我正在嘗試設計一個使用作業行程的程式 - 這只是一個用 C 撰寫的不同程式。
我像這樣啟動一個作業行程:
auto worker = boost::process::child("./worker.exe");
worker->detach();
問題是,作業行程將資訊輸出到它們產生的同一個命令列視窗。這使程式的輸出變得混亂。理想情況下,我希望每個行程都在自己的視窗中運行。
這可以使用 boost::process 嗎?我只找到了有關隱藏視窗的資訊。
我使用的是 Windows 和 Visual Studio 2019。
謝謝
uj5u.com熱心網友回復:
ITNOA
正如您在Boost::process hide console on windows 中看到的那樣,您可以創建用于創建行程的新模式。
CreateProcessA 函式系統呼叫,通過幫助創建標志來展示如何使用新控制臺創建新行程:(CREATE_NEW_CONSOLE感謝使用多個控制臺視窗進行輸出)
您可以撰寫如下代碼
struct new_window
: ::boost::process::detail::handler_base
{
// this function will be invoked at child process constructor before spawning process
template <class WindowsExecutor>
void on_setup(WindowsExecutor &e) const
{
e.creation_flags = ::boost::detail::winapi::CREATE_NEW_CONSOLE_;
}
};
為了使用它,您可以撰寫如下內容
::boost::process::child ch("./worker.exe", new_window);
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/341804.html
