PrevUpHomeNext

Windows specifics

Setting wShowWindow
Unicode
Arbitrary extensions

Use the initializer show_window to set the member variable wShowWindow in STARTUPINFO:

execute(
    run_exe("test.exe"),
    show_window(SW_HIDE)
);

Boost.Process supports Unicode on Windows. If the macro UNICODE or _UNICODE is defined, the Unicode version of CreateProcess is used:

#define UNICODE
#include <boost/process.hpp>
#include <boost/filesystem.hpp>

using namespace boost::process;
using namespace boost::process::initializers;

int main()
{
    boost::filesystem::path p = L"C:\\";
    execute(
        run_exe(L"test.exe"),
        set_cmd_line(L"test --help"),
        start_in_dir(p)
    );
}

On Windows executor calls CreateProcess to start a program. Boost.Process provides three generic initializers to run any code before CreateProcess is called, afterwards if CreateProcess failed and afterwards if CreateProcess succeeded: on_CreateProcess_setup, on_CreateProcess_error and on_CreateProcess_success. These initializers can be used to arbitrarily extend Boost.Process:

execute(
    run_exe("test.exe"),
    on_CreateProcess_setup([](executor &e)
        { e.startup_info.dwFlags = STARTF_RUNFULLSCREEN; }),
    on_CreateProcess_error([](executor&)
        { std::cerr << GetLastError() << std::endl; })
);

The example sets the member variable dwFlags in STARTUPINFO to STARTF_RUNFULLSCREEN. If CreateProcess fails, the system error is written to the standard error stream.

[Note] Note

Boost.Process guarantees to call initializers in the order they are passed to execute. The order is important if several initializers try to set the same member variables in the executor. The initializers provided by Boost.Process have been designed to work correctly no matter which order they are used in. You only have to be careful if you use the generic initializers on_CreateProcess_setup, on_CreateProcess_error and on_CreateProcess_success.


PrevUpHomeNext