'm trying to design a program that uses workers processes - which are just a different program written in C++.
I start a worker process like so:
auto worker = boost::process::child("./worker.exe"); worker->detach();
The issue is, is that the worker processes are outputting information to the same command line window that they are spawned from. This is cluttering the output of the program. Ideally I want each process to run in its own window.
Is this possible using boost::process? I've only found information about hiding the window.
I'm using Windows and Visual Studio 2019.
Thanks
As you can see in Boost::process hide console on windows, you can create new mode for creating process.
CreateProcessA function system call, Show yourself to how to create new process with new console, by helping creation flags: CREATE_NEW_CONSOLE (thanks to Using multiple console windows for output)
you can write code like below
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_; } };
and for using this, you can just write something like below
::boost::process::child ch("./worker.exe", new_window);
Yes, you can do it through handlers https://www.boost.org/doc/libs/1_64_0/doc/html/boost_process/extend.html
Make a handler that adds CREATE_NEW_CONSOLE to creation_flags:
struct new_console : bp::extend::handler {
template <typename Sequence>
void on_setup(bp::extend::windows_executor<char, Sequence> & ex) {
ex.creation_flags |= CREATE_NEW_CONSOLE; } }
Then you can use it as an argument for child creation:
std::error_code ec; boost::process::child child(exe, args, new_console(), ec);
主要是在创建进程时,使用
CREATE_NEW_CONSOLE
这个标签