design.qbk 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. [section:design Design Rationale]
  2. [section Scope]
  3. This library is meant to give an wrapper around the different OS-specific methods
  4. to launch processes. Its aim is to provide all functionality that is available on
  5. those systems and allow the user to do all related things, which require using the OS APIs.
  6. [*This library does not try to provide a full library for everything process related]
  7. In many discussions the proposal was made to build boost.process into a DSEL [footnote Domain Specific Embedded Language] of some sort.
  8. This is not the goal, it rather provides the facilities to build such a DSEL-Library on top of it.
  9. Therefore the library also does [*not] force any particular use (such as only asynchronous communication) on its user.
  10. It rather could be integrated with such a library.
  11. [endsect]
  12. [section Interface Style]
  13. Boost.Process does use a very particular style when constructing a process.
  14. This is because a process holds many properties, which are not members of the actual child class.
  15. Those properties are in many cases not accessible by the father process, for example when using environments.
  16. Here the child process can modify its own environment, but there is no way for the father process to know.
  17. That means, that a child process has properties that cannot be accessed in C++.
  18. This now leads to the two styles supported and mixed by this library. Overloading and properties.
  19. Consider that you may want to launch a process passing a number of arguments. This is supported in both styles, and would look like this:
  20. ```
  21. system("gcc", "--version"); //overloading
  22. system("gcc", args={"--version"}); //property style.
  23. ```
  24. Both styles can also be mixed in some cases.
  25. ```
  26. system("gcc", "-c", args+={"main.cpp"});
  27. ```
  28. In the following section the avaible styles will be described. Note that the
  29. overload style is implemented via type traits, so the types will be listed.
  30. [caution There is no guarantee in which order the arguments will be applied!
  31. There is however a guarantee for arguments belonging together, i.e. the string
  32. argument and the args property will be evaluated in the order given.]
  33. [endsect]
  34. [section:arg_cmd_style Arguments/Command Style]
  35. When passing arguments to the process, two styles are provided, the cmd-style and the exe-/args-style.
  36. The cmd style will interpret the string as a sequence of the exe and arguments and parse them as such, while the exe-/args-style will
  37. interpret each string as an argument.
  38. [table:id Cmd vs Exe/Args
  39. [[String] [Cmd] [Exe/Args]]
  40. [["gcc --version"] [{"gcc", "--version"}] [{"\\"gcc --version\\""}]]
  41. ]
  42. When using the overloading variant, a single string will result in a cmd interpretation,
  43. several strings will yield a exe-args interpretation. Both version can be set explicitly:
  44. ```
  45. system("grep -c false /etc/passwd"); //cmd style
  46. system("grep", "-c", "false", "/etc/passwd"); //exe-/args-
  47. system(cmd="grep -c false /etc/passwd"); //cmd style
  48. system(exe="grep", args={"-c", "false", "/etc/passwd"}); //exe-/args-
  49. ```
  50. [note If a '"' sign is used in the argument style, it will be passed as part of the argument.
  51. If the same effect it wanted with the cmd syntax, it ought to be escaped, i.e. '\\\"'. ]
  52. [note The `PATH` variable will automatically be searched in the command style,
  53. but the one of the launching process, not the one passed to the child process.]
  54. [endsect]
  55. [section:plat_ext Extensions]
  56. The simplest form to extend functionality is to provide another handler, which
  57. will be called on the respective events on process launching. The names are:
  58. *`boost::process::on_setup`
  59. *`boost::process::on_error`
  60. *`boost::process::on_success`
  61. As an example:
  62. ```
  63. child c("ls", on_setup([](){cout << "On Setup" << endl;});
  64. ```
  65. [note On posix all those callbacks will be handled by this process, not the created one.
  66. This is different for the posix extensions, which can be executed on the forked process.]
  67. [endsect]
  68. [endsect]