run.hpp 939 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #pragma once
  2. #include <reproc++/drain.hpp>
  3. #include <reproc++/reproc.hpp>
  4. namespace reproc {
  5. template <typename Out, typename Err>
  6. std::pair<int, std::error_code>
  7. run(const arguments &arguments, const options &options, Out &&out, Err &&err)
  8. {
  9. process process;
  10. std::error_code ec;
  11. ec = process.start(arguments, options);
  12. if (ec) {
  13. return { -1, ec };
  14. }
  15. ec = drain(process, std::forward<Out>(out), std::forward<Err>(err));
  16. if (ec) {
  17. return { -1, ec };
  18. }
  19. return process.stop(options.stop);
  20. }
  21. inline std::pair<int, std::error_code> run(const arguments &arguments,
  22. const options &options = {})
  23. {
  24. struct options modified = options::clone(options);
  25. if (!options.redirect.discard && options.redirect.file == nullptr &&
  26. options.redirect.path == nullptr) {
  27. modified.redirect.parent = true;
  28. }
  29. return run(arguments, modified, sink::null, sink::null);
  30. }
  31. }