Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/463.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在Windows上的node.js中生成子进程时捕获enoint错误,而不使用;shell:true";_Javascript_Node.js_Child Process_Spawn - Fatal编程技术网

Javascript 如何在Windows上的node.js中生成子进程时捕获enoint错误,而不使用;shell:true";

Javascript 如何在Windows上的node.js中生成子进程时捕获enoint错误,而不使用;shell:true";,javascript,node.js,child-process,spawn,Javascript,Node.js,Child Process,Spawn,我正在尝试使用spawn创建一个子进程,并且希望能够处理未找到“cwd”的情况。当找不到它时,它会抛出一个“enoint”错误,在Windows上,只有当我使用“shell:true”属性生成进程时,我才能发现这个错误。所以我现在做的是: const { spawn } = require('child_process') const childProcess = spawn('MyCommand.exe', [], { cwd: path.join(__dirname, 'mypath

我正在尝试使用spawn创建一个子进程,并且希望能够处理未找到“cwd”的情况。当找不到它时,它会抛出一个“enoint”错误,在Windows上,只有当我使用“shell:true”属性生成进程时,我才能发现这个错误。所以我现在做的是:

const { spawn } = require('child_process')
const childProcess = spawn('MyCommand.exe', [], {
    cwd: path.join(__dirname, 'mypath')
}

childProcess.on('error', (err) => {
    // Handle error here
})

childProcess.on('exit', (code, signal) => {
    // Handle exit event
})
在Windows上,除非我执行以下操作,否则上述操作将无法正确捕获eNot异常:

const childProcess = spawn('MyCommand.exe', [], {
    cwd: path.join(__dirname, 'mypath'),
    shell: true
}
如果我使用上述命令生成,那么如果找不到cwd或命令,
exit
事件将捕获异常


但我真的很想不用在shell中运行它就可以做到这一点。有没有办法做到这一点?

对不起,我没有答案,但你给了我一个关于“无错误捕获”的答案。非常感谢。你应该把它贴到Sorry,我没有答案,但你给了我一个关于无误捕捉的答案。非常感谢。你应该把它寄到