# Using 'install(CODE "execute\_process(COMMAND ...' with a shell command

**URL:** <https://discourse.cmake.org/t/using-install-code-execute-process-command-with-a-shell-command/1833>\
**Category:** Code\
**Tags:** os:linux\
**Created:** [September 14, 2020, 7:53am UTC](https://discourse.cmake.org/t/using-install-code-execute-process-command-with-a-shell-command/1833 "2020-09-14T07:53:09Z")\
**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:** [September 14, 2020, 7:53am UTC](https://discourse.cmake.org/t/using-install-code-execute-process-command-with-a-shell-command/1833/1 "2020-09-14T07:53:09Z")

</div>

I’ve used the pattern

` install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E ...`

successfully many times, but I’m having difficulty where the process I want to run is a Bash shell command rather than a CMAKE -E operation.

Specifically, I want to use ‘chrpath’ to modify some imported ELF files generated by SWIG, changing their RPATHs to RUNPATHs. If I use the most obvious form of the syntax,

```
install(CODE "execute_process(COMMAND chrpath --convert ${CMAKE_INSTALL_FULL_BINDIR}/../lib/python2.7/sil/*.so
                              COMMAND_ECHO STDOUT)")

```

…then each block of text between spaces seems to become quoted:

```
'chrpath' '--convert' '<my path>/*.so'
open: No such file or directory
elf_open: Invalid argument

```

… and the command fails.

If, instead, I use the double-bracket syntax (which I can find in examples in various places but doesn’t seem to be documented:)

```
install(CODE [[execute_process(COMMAND chrpath --convert ${CMAKE_INSTALL_FULL_BINDIR}/../lib/python2.7/sil/*.so
                               COMMAND_ECHO STDOUT)]])

```

then it seems to make no difference.

What is the correct syntax to get this to work?

---

<div class="post-metadata">

**Author:** ![Angew](https://discourse.cmake.org/user_avatar/discourse.cmake.org/angew/32/229_2.png) [@Angew](https://discourse.cmake.org/u/Angew)\
**Post date:** [September 14, 2020, 8:30am UTC](https://discourse.cmake.org/t/using-install-code-execute-process-command-with-a-shell-command/1833/2 "2020-09-14T08:30:30Z")

</div>

`execute_process` executes the command directly, not through a shell (quoting the [docs](https://cmake.org/cmake/help/latest/command/execute_process.html): “No intermediate shell is used, so shell operators such as `>` are treated as normal arguments.”). Which means `*` is not expanded (as that is done by the shell), so the argument is a literal `*.so`, and I assume there are no such files in the path.

You should either change the command to launch a shell, or do the “expansion” yourself using something like `file(GLOB)`.

---

<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:** [September 14, 2020, 9:09am UTC](https://discourse.cmake.org/t/using-install-code-execute-process-command-with-a-shell-command/1833/3 "2020-09-14T09:09:14Z")

</div>

Thank you; yes, that does in fact work. I’m afraid I didn’t quite appreciate what the documentation was saying, but using the ‘obvious’ form of the syntax with explicit filenames rather than the wildcard worked successfully. The “${CMAKE\_INSTALL\_FULL\_BINDIR}” was still expanded properly.
