【发布时间】:2019-07-07 10:00:49
【问题描述】:
在 parent.js 中
child = fork(filePath,[],{silent : true});
child.send({
msgtype: "path",
path: path,
options: options,
});
child.stdout.on("data",(data)=>{
console.log(data);
})
在子进程.js中
let createQueue = require("queue-async");
let readdirp = require("readdirp");
process.on("message", function(msg) {
let files = "";
if (msg && msg.msgtype === "path") {
let pathname = msg.path;
files = readdirp(pathname);
process.send({
msg: "detials",
details: msg
});
files.on("error", e => {
process.send({
msg: "killMe",
details: null
});
});
files.on("end", () => {
process.send({
msg: "killMe",
details: null
});
});
files.pipe(process.stdout)
}
});
我的问题我没有错误,并且子进程没有退出。
但是child.stdout.on("data")没有触发,不知道后台发生了什么。
为什么我不能从孩子那里获取数据??我错过了什么,有人可以帮忙吗??
【问题讨论】:
标签: javascript node.js stream