NodeJs Error: spawn C:\Windows\system32\cmd.exe; ENOENT

偶尔善良 提交于 2020-08-03 09:11:22

问题


This is my script :

var exec = require('child_process').exec;

    exec('dir', function(error, stdout, stderr) {  // 'dir' is for example
      if (error) {
        console.error(`exec error: ${error}`);
        return;
      }
      console.log(`stdout: ${stdout}`);
      console.log(`stderr: ${stderr}`);
    });

And in the console I have :

exec error: Error: spawn C:\Windows\system32\cmd.exe; ENOENT

Someone can help me ?


回答1:


I got to resolve the issue the problem is to remove the semicolon(;) from an end of the ComSpec path C:\Windows\System32\cmd.exe

Mycomputer>properties>Advance System Settings>Environment Variables>System Variables

add this path: ComSpec C:\Windows\System32\cmd.exe




回答2:


This can also be caused if you are feeding in ExecOptions the options parameter, specifically 'cwd', and the path you provide is invalid

e.g:

cp.exec(<path_to_executable>, {
  cwd: <path_to_desired_working_dir>
}, (err, stdout, stderr) => {
  //......
})

If is not valid, the callback will be called with err equal to

Error: spawn C:\Windows\system32\cmd.exe ENOENT



来源:https://stackoverflow.com/questions/38458118/nodejs-error-spawn-c-windows-system32-cmd-exe-enoent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!