【发布时间】:2020-05-03 04:36:30
【问题描述】:
正如标题所说,我在尝试为 spawn.stdin.on Uncaught TypeError: spn.stdout.on is not a function 创建事件处理程序时遇到错误。我正在使用 contextBridge ,如下所示,每当我创建一个新的 spawn 对象时,它就会被执行,但是当我创建事件处理程序时它会抛出一个错误。
preload.js
const {contextBridge, remote} = require('electron');
const spawn = require('child_process').spawn;
contextBridge.exposeInMainWorld(
'api', {
spawn: (cmd, args) => {
return spawn(cmd, args);
}
}
);
以及引发错误的函数。
let spn = undefined;
let running = false;
let finishQueueItem = false;
function startQueue() {
// if the queue is already running, then return
if (running) return;
if (!$q.length > 0) {
let x = addToQueue(getConfig());
if (!x) return;
}
running = true;
let $i = $q.pop();
let cmd = $p.DAINPath + "\\DAINAPP.exe";
let args = parseConfig($i);
spn = api.spawn(cmd, args);
spn.stdout.on("data", (data) => {
console.log(data.toString());
});
spn.stderr.on("data", (data) => {
console.error(data.toString());
});
spn.on("exit", (code) => {
console.log("Child process exited with code " + code.toString());
spn = undefined;
running = false;
});
}
【问题讨论】:
-
你的电子版是?可以分享一下 main.js 吗?
-
Electron 版本为 8.0.1。而且大部分的 JavaScript 都在 main_window.html 文件中。github.com/Gigaboy-01/DAIN-Plus
标签: javascript html node.js electron child-process