【发布时间】:2014-01-04 02:21:00
【问题描述】:
我想将一些流数据传输到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)
【问题讨论】:
-
您能否给我们一个示例输入文件/可读流,以便我们可以尝试复制您的问题?另外,您的 gnuplot 和 feedgnuplot 版本是什么?
-
@PaulMougel 我添加了一个可读流的示例。我在 master 运行 gnuplot 4.6 和 feedgnuplot
-
好吧……您的代码示例对我有用(gnuplot 4.6,来自 master 的 feedgnuplot,节点 v0.10.21,Mac Os 10.9),没有
ECONNRESET错误。您的操作系统和 Node.js 版本是多少? -
嘿,我是个白痴,我没有用我在这里发布的那么少的参数来测试我的代码。我在代码中搞砸了 spawn 的参数。感谢您的帮助。
-
如果您已经解决了自己的问题,您可以发布自己的答案并接受。这是目前投票率最高的未回答的 gnuplot 问题。
标签: node.js stream streaming pipe gnuplot