简体   繁体   中英

Unable to get output from child process

So, I have a simple app (I have written) which writes to stdout .

When I run it by itself, the output is being printed fine.

Now, when I spawn the process with node... nothing happens (apart from a message saying the process has finished)

Here's my code:

var spawn = require('child_process').spawn;
helper = spawn("myApp", []);
helper.stdout.on('data', function(data) { 
    console.log("GOT: " + data);
});
helper.stdout.on('end', function(data) {
    console.log("FINISHED: " + data);
});
helper.on('exit', function(code) {
    console.log("CLOSED!");
});

And here's the output:

FINISHED: undefined
CLOSED!

Yep, just that.

What's going on? Am I missing something?

Make sure your stdio output buffers are being flushed in your application:

  fflush(stdout); // or something like that

Output straight to the tty has less buffering than output to a pipe.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM