# execute\_process 'Access is denied' for npm update.

**URL:** https://discourse.cmake.org/t/execute-process-access-is-denied-for-npm-update/10358
**Category:** Code
**Created:** [March 13, 2024, 9:57pm UTC](https://discourse.cmake.org/t/execute-process-access-is-denied-for-npm-update/10358 "2024-03-13T21:57:30Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![marksibly](https://discourse.cmake.org/user_avatar/discourse.cmake.org/marksibly/32/4303_2.png) [@marksibly](https://discourse.cmake.org/u/marksibly)
#### Post date: [March 13, 2024, 9:57pm UTC](https://discourse.cmake.org/t/execute-process-access-is-denied-for-npm-update/10358/1 "2024-03-13T21:57:30Z")

</div>

Hi,

I’m using cmake 3.28.3 on Windows 10 and trying to use execute\_process to call ‘npm update’ after copying package.json to binary dir.

With plain “COMMAND npm update” cmake couldn’t find npm, so I tried using the find\_program path for NPM.

This returns a valid path (“C:/Program Files/nodejs/npm”) but it contains a space which aways gets me hella confused. I tried this:

COMMAND ${NPM\_PATH} update

…and got…

%1 is not a valid Win32 application

I tried this:

COMMAND “${NPM\_PATH}” update

…and got the same thing. I tried this:

COMMAND \“${NPM\_PATH}\” update

…and got…

Access is denied.

I’m guessing I’ve correctly escaped spaces here (and I can sort of see what’s going on having used system() in C myself) but there seems to be a permissions problem of some kind, maybe because the command I want is in Program Files?

I can install the modules globally in the meantime to work around this, but it’d be nice to get the ‘local’ version working.

Does anyone know what’s up and how to fix this?

Bye!  
Mark

---

<div class="post-metadata">

### Author: ![marksibly](https://discourse.cmake.org/user_avatar/discourse.cmake.org/marksibly/32/4303_2.png) [@marksibly](https://discourse.cmake.org/u/marksibly)
#### Post date: [March 13, 2024, 10:35pm UTC](https://discourse.cmake.org/t/execute-process-access-is-denied-for-npm-update/10358/2 "2024-03-13T22:35:03Z")

</div>

OK, I’ve discovered several things, first C:/Program Files/nodejs is actually a shortcut to a dir in C:/Users/etc/AppData/blah…

Futhermore, the file ‘npm’ is bash script. The windows version is called npm.cmd (not npm.bat?)

Kind of suprised I can use ‘npm’ from gitbash/command prompt at all.

The good news is if I use full path to real npm.cmd file, npm update works in cmake.

The bad news this solution will only work for me…

---

<div class="post-metadata">

### Author: ![marksibly](https://discourse.cmake.org/user_avatar/discourse.cmake.org/marksibly/32/4303_2.png) [@marksibly](https://discourse.cmake.org/u/marksibly)
#### Post date: [March 13, 2024, 10:43pm UTC](https://discourse.cmake.org/t/execute-process-access-is-denied-for-npm-update/10358/3 "2024-03-13T22:43:58Z")

</div>

Bingo!

COMMAND cmd /C npm update

---

<div class="post-metadata">

### Author: ![marksibly](https://discourse.cmake.org/user_avatar/discourse.cmake.org/marksibly/32/4303_2.png) [@marksibly](https://discourse.cmake.org/u/marksibly)
#### Post date: [March 13, 2024, 11:18pm UTC](https://discourse.cmake.org/t/execute-process-access-is-denied-for-npm-update/10358/4 "2024-03-13T23:18:47Z")

</div>

But what’s strange is that I don’t have the same problem with “COMMAND npx node-gyp build”…that just works even though npx is in the same dir as npm, is also not a bat file etc etc, they seem to be identical. Might do the cmd /C thing for both…

---

<div class="post-metadata">

### Author: ![jtxa](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jtxa/32/1535_2.png) [@jtxa](https://discourse.cmake.org/u/jtxa)
#### Post date: [March 14, 2024, 12:20am UTC](https://discourse.cmake.org/t/execute-process-access-is-denied-for-npm-update/10358/5 "2024-03-14T00:20:41Z")

</div>

The documentation of `execute_process` explains, that is uses the Windows API directly to execute processes. There is no shell involved.

So any shell script (regardless if `.bat` or `.cmd`), won’t work. You have to call the interpreter explicitly.

Only executables `.exe` or `.com` are supported by Windows API.

---

<div class="post-metadata">

### Author: ![marksibly](https://discourse.cmake.org/user_avatar/discourse.cmake.org/marksibly/32/4303_2.png) [@marksibly](https://discourse.cmake.org/u/marksibly)
#### Post date: [March 14, 2024, 1:10am UTC](https://discourse.cmake.org/t/execute-process-access-is-denied-for-npm-update/10358/6 "2024-03-14T01:10:58Z")

</div>

OK, that explains it, thanks.

On the other hand, add\_custom\_command does seem to ‘use a shell’ (that’s why npx is working) which I think is what have may initially have confused me.
