# add\_custom\_command with multiple commands on windows

**URL:** <https://discourse.cmake.org/t/add-custom-command-with-multiple-commands-on-windows/6604>\
**Category:** Code\
**Tags:** os:windows\
**Created:** [October 5, 2022, 2:49pm UTC](https://discourse.cmake.org/t/add-custom-command-with-multiple-commands-on-windows/6604 "2022-10-05T14:49:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![codeling](https://discourse.cmake.org/user_avatar/discourse.cmake.org/codeling/32/1700_2.png) [@codeling](https://discourse.cmake.org/u/codeling)\
**Post date:** [October 5, 2022, 2:49pm UTC](https://discourse.cmake.org/t/add-custom-command-with-multiple-commands-on-windows/6604/1 "2022-10-05T14:49:08Z")

</div>

I just noticed that when I do an `add_custom_command` on Windows (Visual Studio Generator, tested with 2019 and 2022), and I want to execute multiple commands for a “build step” (e.g. POST\_BUILD) (or if there is another command added somewhere else, such as from automatic moc’ing), I need to prefix the command that I want to execute with `call`, otherwise the only one of the commands (the first one) will be executed; Visual Studio stops after the first command, without reporting any errors.

Is this something known? I couldn’t find anything on this so far, but also would expect I am not the only one needing something like this to work. The inspiration for trying call came [from this stackoverflow question](https://stackoverflow.com/questions/3686837/why-are-my-custom-build-steps-not-running-in-visual-studio). The [Microsoft documentation on call](https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/call) seems to only mention it in the context of calling batch scripts, but I can confirm it also works with calling executables (.exe).

Maybe this should be documented in the `add_custom_command` documentation?

---

<div class="post-metadata">

**Author:** ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)\
**Post date:** [October 7, 2022, 5:46am UTC](https://discourse.cmake.org/t/add-custom-command-with-multiple-commands-on-windows/6604/2 "2022-10-07T05:46:24Z")

</div>

Please provide a complete, minimal example project which shows what you expect to work. Be sure to make clear what each command being invoked is as well (executable, batch file, etc.). The details of those things may be important.

---

<div class="post-metadata">

**Author:** ![codeling](https://discourse.cmake.org/user_avatar/discourse.cmake.org/codeling/32/1700_2.png) [@codeling](https://discourse.cmake.org/u/codeling)\
**Post date:** [October 11, 2022, 3:04pm UTC](https://discourse.cmake.org/t/add-custom-command-with-multiple-commands-on-windows/6604/3 "2022-10-11T15:04:25Z")

</div>

Good point, should have thought of that before! On trying to reproduce the problem, I realized that what I am calling (what I thought were executables) are actually .cmd files. Having to use `call` for those in order not to abort subsequent steps is to be expected on Windows, I guess…
