# Wait for execute\_process to finish

**URL:** <https://discourse.cmake.org/t/wait-for-execute-process-to-finish/7191>\
**Category:** Code\
**Created:** [January 4, 2023, 12:37pm UTC](https://discourse.cmake.org/t/wait-for-execute-process-to-finish/7191 "2023-01-04T12:37:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![some\_name](https://discourse.cmake.org/user_avatar/discourse.cmake.org/some_name/32/3023_2.png) [@some\_name](https://discourse.cmake.org/u/some_name)\
**Post date:** [January 4, 2023, 12:37pm UTC](https://discourse.cmake.org/t/wait-for-execute-process-to-finish/7191/1 "2023-01-04T12:37:34Z")

</div>

My project depends on external libraries such as Boost, GTest, and GMock. I am providing a facility wherein a user can pass a variable BINARY\_ROOT from the command line, and if FindBoost, FindGTest etc fail, it will automatically decompress the appropriate binary, compile, and install it, then try FindBoost etc again.

Each library requires multiple steps to be executed one after the other. For example, boost requires b2.exe to be produced first. I am able to successfully build it with the command

execute\_process(  
COMMAND cmd /C “${ScriptCmd}”  
WORKING\_DIRECTORY “${WorkingDirectory}”  
COMMAND\_ECHO STDOUT  
)

I then issue

execute\_process(  
COMMAND “${FullB2Cmd}”  
WORKING\_DIRECTORY “${BootstrapDir}”  
COMMAND\_ECHO STDOUT  
COMMAND\_ERROR\_IS\_FATAL ANY  
)

Unfortunately, this second command fails with:

‘C:\DemoBinaries\Temp\boost\_1\_81\_0\b2 --prefix=C:\DemoPackages\Boost variant=debug variant=release --build-type=complete install’  
CMake Error at cmake/boost\_utility.cmake:16 (execute\_process):  
execute\_process error getting child return code: The system cannot find the  
file specified

The console output clearly shows that the first command executes quite successfully, but it seems CMake is not waiting for it to finish the compilation process. How can I make CMake wait for execute\_process to finish before executing the next command?

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [January 4, 2023, 2:10pm UTC](https://discourse.cmake.org/t/wait-for-execute-process-to-finish/7191/2 "2023-01-04T14:10:12Z")

</div>

CMake always waits for the command to complete today. I think the problem is that you’ve quoted `${FullB2Cmd}` which means it is trying to execute `C:\DemoBinaries\Temp\boost_1_81_0\b2 --prefix=C:\DemoPackages\Boost variant=debug variant=release --build-type=complete install` as `argv[0]`, not a set of command line arguments. Or use `cmd /C` as you did for the bootstrap.
