# Quotations in ctest scripts and proper usage of MPIEXEC\_PREFLAGS

**URL:** https://discourse.cmake.org/t/quotations-in-ctest-scripts-and-proper-usage-of-mpiexec-preflags/338
**Category:** Code
**Created:** [December 9, 2019, 6:35pm UTC](https://discourse.cmake.org/t/quotations-in-ctest-scripts-and-proper-usage-of-mpiexec-preflags/338 "2019-12-09T18:35:56Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![David\_Dixon](https://discourse.cmake.org/user_avatar/discourse.cmake.org/david_dixon/32/127_2.png) [@David\_Dixon](https://discourse.cmake.org/u/David_Dixon)
#### Post date: [December 9, 2019, 6:35pm UTC](https://discourse.cmake.org/t/quotations-in-ctest-scripts-and-proper-usage-of-mpiexec-preflags/338/1 "2019-12-09T18:35:56Z")

</div>

I use `MPIEXEC_PREFLAGS` when adding a test as described in the FindMPI documentation. For example:

```auto
add_test( 
  NAME mytest 
  COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} 4
  ${MPIEXEC_PREFLAGS} mytest ${MPIEXEC_POSTFLAGS}
)

```

When configuring with `-D MPIEXEC_PREFLAGS="--bind-to none"` I find that the test command above fails because the following command is generated:

```auto
mpiexec "-n" "4" "--bind-to none" mytest

```

and `"--bind-to none"` is the point of failure. What does work is `-D MPIEXEC_PREFLAGS="--bind-to;none"` which generates the following command:

```auto
mpiexec "-n" "4" "--bind-to" "none" mytest

```

Note that `"--bind-to none"` is now `"--bind-to" "none"`.

This issue is further complicated in the context of CI when setting the `CTEST_CONFIGURE_COMMAND` in my ctest script. The closest I’ve cometo getting it right is:

```auto
set(CTEST_CONFIGURE_COMMAND "cmake -D MPIEXEC_PREFLAGS=\"--bind-to;none\""

```

which gives the following output when running `ctest -VV -S myscript.cmake:

```auto
Configure with command: cmake -D MPIEXEC_PREFLAGS="--bind-to;none"
Run command: "cmake" "-D" "MPIEXEC_PREFLAGS="--bind-to;none""

```

First, I wonder if I should use `MPIEXEC_PREFLAGS` this way - I don’t see any strict guidance in the documentation on how to use the variable.

If I am using it (and not abusing it), then how do I fix the quotation nightmare?

Thanks!

---

<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: [December 9, 2019, 7:37pm UTC](https://discourse.cmake.org/t/quotations-in-ctest-scripts-and-proper-usage-of-mpiexec-preflags/338/2 "2019-12-09T19:37:13Z")

</div>

Hmm. I think those are generally filled out by `FindMPI`. They’re supposed to be lists. Does this work?

```cmake
set(CTEST_CONFIGURE_COMMAND "cmake -D MPIEXEC_PREFLAGS=--bind-to;none")

```

---

<div class="post-metadata">

### Author: ![David\_Dixon](https://discourse.cmake.org/user_avatar/discourse.cmake.org/david_dixon/32/127_2.png) [@David\_Dixon](https://discourse.cmake.org/u/David_Dixon)
#### Post date: [December 10, 2019, 1:38pm UTC](https://discourse.cmake.org/t/quotations-in-ctest-scripts-and-proper-usage-of-mpiexec-preflags/338/3 "2019-12-10T13:38:37Z")

</div>

That doesn’t work either the run command winds up being:

```auto
"cmake" "-D" "MPIEXEC_PREFLAGS=--bind-to;none"

```

---

<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: [February 15, 2020, 11:20pm UTC](https://discourse.cmake.org/t/quotations-in-ctest-scripts-and-proper-usage-of-mpiexec-preflags/338/4 "2020-02-15T23:20:11Z")

</div>

Escaping of the `;` may be necessary here. My guidance for these quoting issues is usually to follow the value through all the layers to see where escaping is necessary or messing other things up. It’s hard to give a specific answer without knowing everywhere the string ends up existing (here, probably something like YAML → shell → CMake script → CMake command line → CMake code → command list in `add_custom_command` and/or `add_test` → `CTestTestfile` → final shell).
