管道到产卵标准

时间:2013-12-16 16:01:43

标签: node.js stream streaming pipe gnuplot

我想将一些流数据传输到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错误

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

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)

1 个答案:

答案 0 :(得分:0)

对我来说,使用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)

如果从终端呼叫nodejs index.js