postup_commands.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #include "postup_commands.hpp"
  2. void PostupCommands::add_postup_command(const std::string& command)
  3. {
  4. this->_postup_commands.push_back(command);
  5. }
  6. void PostupCommands::execute_commands() const
  7. {
  8. for (const auto& postup_command : this->_postup_commands)
  9. {
  10. BOOST_LOG_TRIVIAL(debug)
  11. << "Execute post up command: " << postup_command << std::endl;
  12. std::error_code ec;
  13. boost::process::child child(
  14. postup_command,
  15. boost::process::std_out > boost::process::null,
  16. boost::process::std_err > boost::process::null,
  17. ec);
  18. child.wait();
  19. BOOST_LOG_TRIVIAL(debug)
  20. << "Post up command result: " << child.exit_code() << std::endl;
  21. if (child.exit_code() != 0 || ec)
  22. {
  23. if (ec)
  24. {
  25. BOOST_LOG_TRIVIAL(fatal)
  26. << "Failed to execute post up command: " << ec.message()
  27. << std::endl;
  28. }
  29. throw std::runtime_error("Failed to execute post up command.");
  30. }
  31. }
  32. }