I'm using child process fork but I'm not able to pipe child console logs to parent's dev tools

176 views
Skip to first unread message

nagraj...@gmail.com

unread,
Sep 9, 2016, 7:37:05 AM9/9/16
to nw.js
This is my code:

1. index.html:

            var childprocess = nw.require('child_process');
            var worker = childprocess.fork('worker.js', [], {silent:true});
            worker.stdout.on('data', function(data) { console.log(String(data)); });
            worker.stderr.on('data', function(data) { console.error(String(data)); });
            worker.on('error', function(err) { console.error(err); });
            worker.on('message',function(msg){console.log(msg)});

2. worker.js:
        process.send("woah");
        process.send('starting child process');
        process.stdout.write("tuntak");
        process.send('starting child process');
        console.log("ha ha");
        process.on('message', function (m) {
            console.log('received message from parent: ');
            process.send(m);  
        });


The output I get on console is :






All I want is the console log to appear in dev tools.


It says to use pipe,I've tried using pipe,inherit and other combination like:

1)child = child_process.fork('./cp.js', {stdio: ['pipe','pipe','pipe']}); child.stdio output is [null,null,null,null] 2)child = child_process.fork('./cp.js', {stdio: ['inherit','inherit','inherit']});
child.stdio output is [null,null,null,null]
3)child = child_process.fork('./cp.js', {
    stdio: [
      0, // Use parents stdin for child
      'pipe', // Pipe child's stdout to parent
      fs.openSync('err.out', 'w') // Direct child's stderr to a file
    ]
});
child.stdio output is [null,null,null,null]. Please point out if something is wrong here.

yunkw...@gmail.com

unread,
Nov 2, 2016, 5:29:03 AM11/2/16
to nw.js, nagraj...@gmail.com
hi,

i want to get console.log from child process of seperated node app.
and i faced to same problem like you, even i used the latest nwjs version v0.18.4 on window.
only stdio was set to Socket, when {silent:true}. but no different between using pipe and inherit.

did you solve this problem?


2016년 9월 9일 금요일 오후 8시 37분 5초 UTC+9, nagraj...@gmail.com 님의 말:
Reply all
Reply to author
Forward
0 new messages