# Syntax for execute\_process with two executables in command line

**URL:** https://discourse.cmake.org/t/syntax-for-execute-process-with-two-executables-in-command-line/10141
**Category:** Usage
**Created:** [February 21, 2024, 2:16am UTC](https://discourse.cmake.org/t/syntax-for-execute-process-with-two-executables-in-command-line/10141 "2024-02-21T02:16:24Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![EosPengwern](https://discourse.cmake.org/user_avatar/discourse.cmake.org/eospengwern/32/3904_2.png) [@EosPengwern](https://discourse.cmake.org/u/EosPengwern)
#### Post date: [February 21, 2024, 2:16am UTC](https://discourse.cmake.org/t/syntax-for-execute-process-with-two-executables-in-command-line/10141/1 "2024-02-21T02:16:24Z")

</div>

In my cmake file, there is a line of the form:

```auto
  execute_process(COMMAND cmake -E echo "Executing: my_application.exe file_being_analysed.exe --output results_dir"
                  COMMAND my_application.exe file_being_analysed.exe --output results_dir)

```

In Linux, this works: no problems.

In Windows, I get an error message:

```auto
 Error: Only one binary file can be specified.

```

…which presumably arises from the fact that the two executable files - the one doing the analysis and the one being analysed - occur on the same command line.

The command itself is correct: if I run it exactly as-is from the Windows command line, then it works. This is the required syntax: I can’t change it. So how can I run it from within execute\_process?

I’ve tried enclosing everything after the second COMMAND in quotations; I’ve even tried enclosing everything _including_ the second COMMAND in quotations. In the former case, the whole execute\_process command seems to be silently ignored (i.e. not even the ‘echo’ takes place), while in the latter case the whole contents of execute\_process is echoed but nothing is executed.

What am I missing?

---

<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: [February 21, 2024, 10:57pm UTC](https://discourse.cmake.org/t/syntax-for-execute-process-with-two-executables-in-command-line/10141/2 "2024-02-21T22:57:41Z")

</div>

Note that when you specify more than one `COMMAND` with `execute_process()`, the two commands are run as one pipeline. The output from the first command is fed as input to the second. This is different to `add_custom_command()` and `add_custom_target()` where multiple `COMMAND` items are executed separately and in order.

Try separating out the commands into two separate `execute_process()` calls and see if that changes your situation. I also recommend you check for errors for each one (the `COMMAND_ERROR_IS_FATAL` keyword makes that easy):

```cmake
execute_process(COMMAND cmake -E echo "Executing: my_application.exe file_being_analysed.exe --output results_dir"
    COMMAND_ERROR_IS_FATAL LAST
)

execute_process(COMMAND my_application.exe file_being_analysed.exe --output results_dir
    COMMAND_ERROR_IS_FATAL LAST
)

```

---

<div class="post-metadata">

### Author: ![EosPengwern](https://discourse.cmake.org/user_avatar/discourse.cmake.org/eospengwern/32/3904_2.png) [@EosPengwern](https://discourse.cmake.org/u/EosPengwern)
#### Post date: [February 21, 2024, 11:15pm UTC](https://discourse.cmake.org/t/syntax-for-execute-process-with-two-executables-in-command-line/10141/3 "2024-02-21T23:15:31Z")

</div>

Thank you; yes, it works now.

I think I had misunderstood the original problem, but doing what you suggested helped me to flush it out.

In the _real_ code (as opposed to my [over]simplified example), the actual command being executed is represented as a variable, and it turned out that that string did indeed contain another command, _after_ the one I’d showed, but _only in Windows_ - in Linux the variable did not contain that extra command.

So in fact, now I understand that, it appears that in fact:

```auto
execute_process(COMMAND cmake -E echo "Executing: my_application.exe file_being_analysed.exe --output results_dir"
                  COMMAND my_application.exe file_being_analysed.exe --output results_dir)

```

…is absolutely fine, on Windows as well as Linux. This wasn’t CMake’s fault!
