# PATCH\_COMMAND stopped working 3.27.7 --\> 3.30.5

**URL:** <https://discourse.cmake.org/t/patch-command-stopped-working-3-27-7-3-30-5/13287>\
**Category:** Code\
**Tags:** os:linux\
**Created:** [December 29, 2024, 11:12pm UTC](https://discourse.cmake.org/t/patch-command-stopped-working-3-27-7-3-30-5/13287 "2024-12-29T23:12:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nncarlson](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/n/ed655f/32.png) [@nncarlson](https://discourse.cmake.org/u/nncarlson)\
**Post date:** [December 29, 2024, 11:12pm UTC](https://discourse.cmake.org/t/patch-command-stopped-working-3-27-7-3-30-5/13287/1 "2024-12-29T23:12:18Z")

</div>

I have the following command to download a tar.gz file, unpack it, and apply a patch file:

```cmake
FetchContent_Populate(${PROJECT_NAME} URL ${url}
   PATCH_COMMAND patch -p1 < ${PROJECT_SOURCE_DIR}/mumps-nag.patch)

```

This works as expected with cmake 3.27.7. But with version 3.30.5 it fails with the following error:

```auto
patching file '<'
Hunk #1 FAILED at 51.
patch: **** Can't reopen file '<' : No such file or directory

```

It appears that ‘\<’ is being interpreted as a file name rather than redirecting stdin from the file. Has something intentional changed between 3.27.7 and 3.30.5? In another project we use the same kind of PATCH\_COMMAND but inside an `externalproject_add` and it works fine there with 3.30.5. I’m stumped.

---

<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:** [December 30, 2024, 9:26pm UTC](https://discourse.cmake.org/t/patch-command-stopped-working-3-27-7-3-30-5/13287/2 "2024-12-30T21:26:57Z")

</div>

Commands in FetchContent and ExternalProject are not guaranteed to be executed using any particular shell, or even any shell at all. You’re relying on `<` being treated as a redirection operator by a shell, but that has never been safe to do, nor guaranteed to work. Put your command in a script and run that script instead if it needs to use shell features. Even better, you can invoke the `patch` command with appropriate command line options such that you don’t need the `<` operator at all.

There have been a lot of changes with FetchContent in the last couple of CMake feature releases. Your example looks like it has been taken from a project rather than a CMake script file. The FetchContent documentation explicitly states that the form of `FetchContent_Populate()` you’re using should only be used in CMake script mode, and CMake 3.30 deprecated the other (single-argument) form of `FetchContent_Populate()` altogether (see [CMP0169](https://cmake.org/cmake/help/latest/policy/CMP0169.html)). If you’ve updated your project’s policy settings, you might also be seeing an effect of [CMP0168](https://cmake.org/cmake/help/latest/policy/CMP0168.html), although this seems less likely.

---

<div class="post-metadata">

**Author:** ![nncarlson](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/n/ed655f/32.png) [@nncarlson](https://discourse.cmake.org/u/nncarlson)\
**Post date:** [December 30, 2024, 9:58pm UTC](https://discourse.cmake.org/t/patch-command-stopped-working-3-27-7-3-30-5/13287/3 "2024-12-30T21:58:57Z")

</div>

Thanks for the detailed explanation. Yes this was from a project (from someone else) that I need to modify. I know what I need to do now, thanks!
