[英]Unable to get output from child process
So, I have a simple app (I have written) which writes to stdout
. 因此,我有一个简单的应用程序(已编写),该应用程序可以写入
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: 确保在您的应用程序中刷新了stdio输出缓冲区:
fflush(stdout); // or something like that
Output straight to the tty has less buffering than output to a pipe. 直接输出到tty的缓冲少于输出到管道的缓冲。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.