pipe道到一个spawn stdin

我想pipe一些stream数据到feedgnuplot为了实时绘制它

以下工作:

// index.js readableStream.pipe(process.stdout) // in bash $ node index.js | feedgnuplot --stream 

但是下面的行不通(这就是我想要做的):

 // index.js var feedgnuplot = require('child_process').spawn('feedgnuplot', ['--stream']) readableStream.pipe(feedgnuplot.stdin) //in bash $ node index.js 

我收到ECONNRESET错误

编辑:请求可读stream的示例:

 var util = require('util') var Readable = require('stream').Readable util.inherits(SomeReadableStream, Readable) function SomeReadableStream () { Readable.call(this) } SomeReadableStream.prototype._read = function () { this.push(Math.random().toString()+'\n') } var someReadableStream = new SomeReadableStream() someReadableStream.pipe(process.stdout) 

对于我来说,使用node.js v0.10.26,你的脚本工作正常:

脚本index.js

 var util = require('util') var Readable = require('stream').Readable util.inherits(SomeReadableStream, Readable) function SomeReadableStream () { Readable.call(this) } SomeReadableStream.prototype._read = function () { this.push(Math.random().toString()+'\n') } var someReadableStream = new SomeReadableStream() var feedgnuplot = require('child_process').spawn('feedgnuplot', ['--stream']) someReadableStream.pipe(feedgnuplot.stdin) 

并从terminal调用if为nodejs index.js