我有一个简单的节点子进程,它调用一个脚本,该脚本需要时间来输出一些信息(有点像ping
的工作方式(。
let command = spawn(
execPath,
[...args],
{ cwd: null, detached: false }
);
然后我为stdout做一个标准的console.log:
command.stdout.on("data", (stdout) => {
console.log("Realtime Output: ", stdout.toString());
});
问题是,我想把这个实时输出发送回渲染器进程,并在前端显示它。我尝试在command.stdout.on()
中添加一个ipcRenderer.send()
,但不起作用,前端在console.log中显示undefined
有什么办法做到这一点吗?
您必须通过webContents 从mainWindow
发送stdout
mainWindow.webContents.send('output', stdout.toString())