1
0

execute_process.rst 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. execute_process
  2. ---------------
  3. Execute one or more child processes.
  4. .. code-block:: cmake
  5. execute_process(COMMAND <cmd1> [args1...]]
  6. [COMMAND <cmd2> [args2...] [...]]
  7. [WORKING_DIRECTORY <directory>]
  8. [TIMEOUT <seconds>]
  9. [RESULT_VARIABLE <variable>]
  10. [OUTPUT_VARIABLE <variable>]
  11. [ERROR_VARIABLE <variable>]
  12. [INPUT_FILE <file>]
  13. [OUTPUT_FILE <file>]
  14. [ERROR_FILE <file>]
  15. [OUTPUT_QUIET]
  16. [ERROR_QUIET]
  17. [OUTPUT_STRIP_TRAILING_WHITESPACE]
  18. [ERROR_STRIP_TRAILING_WHITESPACE])
  19. Runs the given sequence of one or more commands in parallel with the standard
  20. output of each process piped to the standard input of the next.
  21. A single standard error pipe is used for all processes.
  22. Options:
  23. ``COMMAND``
  24. A child process command line.
  25. CMake executes the child process using operating system APIs directly.
  26. All arguments are passed VERBATIM to the child process.
  27. No intermediate shell is used, so shell operators such as ``>``
  28. are treated as normal arguments.
  29. (Use the ``INPUT_*``, ``OUTPUT_*``, and ``ERROR_*`` options to
  30. redirect stdin, stdout, and stderr.)
  31. If a sequential execution of multiple commands is required, use multiple
  32. :command:`execute_process` calls with a single ``COMMAND`` argument.
  33. ``WORKING_DIRECTORY``
  34. The named directory will be set as the current working directory of
  35. the child processes.
  36. ``TIMEOUT``
  37. The child processes will be terminated if they do not finish in the
  38. specified number of seconds (fractions are allowed).
  39. ``RESULT_VARIABLE``
  40. The variable will be set to contain the result of running the processes.
  41. This will be an integer return code from the last child or a string
  42. describing an error condition.
  43. ``OUTPUT_VARIABLE``, ``ERROR_VARIABLE``
  44. The variable named will be set with the contents of the standard output
  45. and standard error pipes, respectively. If the same variable is named
  46. for both pipes their output will be merged in the order produced.
  47. ``INPUT_FILE, OUTPUT_FILE``, ``ERROR_FILE``
  48. The file named will be attached to the standard input of the first
  49. process, standard output of the last process, or standard error of
  50. all processes, respectively. If the same file is named for both
  51. output and error then it will be used for both.
  52. ``OUTPUT_QUIET``, ``ERROR_QUIET``
  53. The standard output or standard error results will be quietly ignored.
  54. If more than one ``OUTPUT_*`` or ``ERROR_*`` option is given for the
  55. same pipe the precedence is not specified.
  56. If no ``OUTPUT_*`` or ``ERROR_*`` options are given the output will
  57. be shared with the corresponding pipes of the CMake process itself.
  58. The :command:`execute_process` command is a newer more powerful version of
  59. :command:`exec_program`, but the old command has been kept for compatibility.
  60. Both commands run while CMake is processing the project prior to build
  61. system generation. Use :command:`add_custom_target` and
  62. :command:`add_custom_command` to create custom commands that run at
  63. build time.