[英]NodeJs Error: spawn C:\Windows\system32\cmd.exe; ENOENT
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 ?有人可以帮助我吗?
This can also be caused if you are feeding in ExecOptions the options parameter, specifically 'cwd', and the path you provide is invalid如果您在 ExecOptions 中提供 options 参数,特别是“cwd”,并且您提供的路径无效,也会导致这种情况
eg:例如:
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
错误:生成 C:\\Windows\\system32\\cmd.exe ENOENT
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我必须解决这个问题,问题是从 ComSpec 路径 C:\\Windows\\System32\\cmd.exe 的末尾删除分号(;)
Mycomputer>properties>Advance System Settings>Environment Variables>System Variables我的电脑>属性>高级系统设置>环境变量>系统变量
add this path:添加此路径:
ComSpec C:\\Windows\\System32\\cmd.exe
ComSpec C:\\Windows\\System32\\cmd.exe
For any one still having issues with this对于仍然有此问题的任何人
What fixed it for me was that my solution directory was on a different drive than windows Creating my solution on my C drive solved the issue for me对我来说修复的是我的解决方案目录与 Windows 在不同的驱动器上创建我的解决方案在我的 C 驱动器上为我解决了这个问题
Increasing the maxBuffer solved the problem for me.增加 maxBuffer 为我解决了这个问题。
const child_process = require('child_process');
var command = 'git ls-files . --ignored --exclude-standard --others';
child_process.execSync(command, {
maxBuffer: 1024 ** 6,
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.