无法从派生子进程获取数据

时间:2019-07-06 15:08:28

标签: javascript node.js stream pipe

在parent.js中

child = fork(filePath,[],{silent : true}); child.send({ msgtype: "path", path: path, options: options, }); **child.stdout.on("data",(data)=>{ console.log(data); })** 在子process.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”)没有触发,我不知道后台会发生什么。

为什么我不能从孩子那里得到数据?我想念什么,任何人都可以帮忙吗?

0 个答案:

没有答案
相关问题