How to use v2 initializers

Open
#466 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
25/100
Issue type
Documentation
Clarity
Needs clarification
Activity status
Stale
Tech stack
cpp
Domain
documentation

Research direction

Start with the Boost.Process v2 process initializer API, especially the CustomInit hook methods and the async_execute entry point shown in the example. Determine whether the hooks are expected to run in this usage, then document the correct initializer pattern and a working example; no specific file or test is named in the issue.

Written by the indexing model from the issue text.

Description

Hello,

I am excited to use process v2 in my projects. Unfortunately I am having a bit of a hard time understanding the API. If this is not the correct place to post such questions I apologize.

Please see my following example. I cannot get the on_* functions to run. I am sure I am doing something wrong:

namespace asio = boost::asio;
namespace bp = boost::process::v2;
using namespace std::chrono_literals;

struct CustomInit
{
   template <typename Launcher>
   std::error_code on_setup(Launcher&, const std::filesystem::path&, const char * const *&)
   {
      std::cout << "on_setup" << std::endl;
      return {};
   }

   template <typename Launcher>
   std::error_code on_error(Launcher&, const std::filesystem::path&, const char * const *&)
   {
      std::cout << "on_error" << std::endl;
      return {};
   }

   template <typename Launcher>
   std::error_code on_success(Launcher&, const std::filesystem::path&, const char * const *&)
   {
      std::cout << "on_success" << std::endl;
      return {};
   }

   template <typename Launcher>
   std::error_code on_fork_error(Launcher&, const std::filesystem::path&, const char * const *&)
   {
      std::cout << "on_fork_error" << std::endl;
      return {};
   }

   template <typename Launcher>
   std::error_code on_exec_setup(Launcher&, const std::filesystem::path&, const char * const *&)
   {
      std::cout << "on_exec_setup" << std::endl;
      return {};
   }

   template <typename Launcher>
   std::error_code on_exec_error(Launcher&, const std::filesystem::path&, const char * const *&)
   {
      std::cout << "on_exec_error" << std::endl;
      return {};
   }
};

int
main(void)
{
   asio::io_context io;
   
   try {
      auto p = bp::process(io, "/usr/bin/sleep", {"1"}, CustomInit{});

      bp::async_execute(std::move(p),
      [] (const boost::system::error_code &, const int exitCode) {
         std::cout << exitCode << std::endl;
      });

      io.run();
   }
   catch (const std::exception &e) {
      std::cerr << e.what() << std::endl;
   }

   return 0;
}

Thanks in advance for any assistance you can provide.

Dominant language
C++
Stars
145
Forks
151
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from boostorg/process

All issues in boostorg/process

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.