find-process
find-process copied to clipboard
spawn cmd ENOENT on Windows Server 2016
Hello,
One of our users is having trouble with an ENOENT being thrown by find-process
, indicating that WMIC could not be found:
cypress-io/cypress#3912
Here is the text of the error, for reference:
Error: spawn cmd ENOENT
at exports._errnoException (util.js:1024:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:192:19)
at onErrorNT (internal/child_process.js:374:16)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
code: 'ENOENT',
errno: 'ENOENT',
syscall: 'spawn cmd',
path: 'cmd',
spawnargs:
[ '/c',
'WMIC path win32_process get Name,Processid,ParentProcessId,Commandline' ] }
Error: spawn cmd ENOENT
at exports._errnoException (util.js:1024:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:192:19)
at onErrorNT (internal/child_process.js:374:16)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
Is this a known issue that there's a workaround for?
Supposedly this can happen on Windows because of something to do with filename extensions: https://stackoverflow.com/questions/27688804/how-do-i-debug-error-spawn-enoent-on-node-js
I think that if you simply changed the cmd
to cmd.exe
on this line, the error might go away:
https://github.com/yibn2008/find-process/blob/62c9211c691e8ee46169b6df5e15a33c47f3aa23/lib/find_process.js#L123
@flotwig Is this not related to this issue? https://github.com/yibn2008/find-process/issues/9 Cypress is updating to the version that contains this fix, so it may fix this issue https://github.com/cypress-io/cypress/pull/4087
@jennifer-shehane I don't think it's the same issue, this error was actually crashing the process
Supposedly this can happen on Windows because of something to do with filename extensions: https://stackoverflow.com/questions/27688804/how-do-i-debug-error-spawn-enoent-on-node-js
I think that if you simply changed the
cmd
tocmd.exe
on this line, the error might go away:https://github.com/yibn2008/find-process/blob/62c9211c691e8ee46169b6df5e15a33c47f3aa23/lib/find_process.js#L123
I don't have the environment to reproduce this issue, please verify if this change can fix the problem.
I haven't been able to reproduce it either :/
This actually seems to be happening when the user does not have C:\Windows\System32
in their PATH
:
- https://github.com/cypress-io/cypress/issues/4260#issuecomment-507771133
- https://github.com/cypress-io/cypress/issues/3093#issuecomment-452434092
- https://github.com/cypress-io/cypress/issues/3912#issuecomment-499998694
- https://stackoverflow.com/questions/28624686/get-spawn-cmd-enoent-when-try-to-build-cordova-application-event-js85
Would changing that line to the following be a good solution?
const proc = utils.spawn('C:\Windows\System32\cmd.exe', ['/c', cmd], { detached: false, windowsHide: true })
The error in windows is reproduced if the path to C:\Windows\System32 is missing in the system PATH variable. The path can be restored in this way:
const CMDPath = path.resolve(env.WINDIR, path.sep+'system32');
const pathArray = (env?.PATH || '').split(path.delimiter);
pathArray.push(CMDPath);
process.env.PATH = pathArray.join(path.delimiter);