spawn无法在node.js中启动全局包
我需要通过另一个名为launcher的全局包来启动全局安装的节点包作为一个独立的进程。 我想让启动器启动另一个软件包并退出。
产卵能够启动记事本作为单独的过程。 但是无法启动全球安装的软件包。
我写了下面的代码:
//var child = moduleLauncher.spawn('notepad',[],{ var child = moduleLauncher.spawn('hrm_module C:/test.scanRequest',[],{ detached: true, stdio: ['ignore', out, err] }); child.unref();
生成的错误:
events.js:154 throw er; // Unhandled 'error' event ^ Error: spawn hrm_module C:/test.scanRequest ENOENT at exports._errnoException (util.js:856:11) at Process.ChildProcess._handle.onexit (internal/child_process.js:178:32) at onErrorNT (internal/child_process.js:344:16) at nextTickCallbackWith2Args (node.js:475:9) at process._tickCallback (node.js:389:17) at Function.Module.runMain (module.js:449:11) at startup (node.js:140:18) at node.js:1001:3
注意: hrm_module C:/test.scanRequest
– hrm_module C:/test.scanRequest
在windows命令提示符下工作正常。
我想通过启动器运行这个命令。
spawn('hrm_module C:/test.scanRequest',[]
需要是
spawn('hrm_module',['C:/test.scanRequest']
将parameter passing给参数数组。 否则,它将查找名为hrm_module C:/test.scanRequest
的文件,并找不到您find的文件。
让cmd
为你启动模块:
const command = 'cmd'; const args = ['/C', 'hrm_module', 'C:/test.scanRequest'] const options = {/* your spawn options */ }; spawn(command, args, options);