Home > Software design >  Boost process open process in new window (Windows)
Boost process open process in new window (Windows)

Time:10-30

I'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

CodePudding user response:

ITNOA

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);
  • Related