sta*_*m87 6 streaming gnuplot pipe stream node.js
我想将一些流数据传输到feedgnuplot,以便实时绘制图形
以下作品:
// index.js
readableStream.pipe(process.stdout)
// in bash
$ node index.js | feedgnuplot --stream
Run Code Online (Sandbox Code Playgroud)
但以下不起作用(这就是我想要的工作):
// index.js
var feedgnuplot = require('child_process').spawn('feedgnuplot', ['--stream'])
readableStream.pipe(feedgnuplot.stdin)
//in bash
$ node index.js
Run Code Online (Sandbox Code Playgroud)
我收到了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)
Run Code Online (Sandbox Code Playgroud)
对我来说,使用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)
Run Code Online (Sandbox Code Playgroud)
并从终端调用 if 为nodejs index.js。
| 归档时间: |
|
| 查看次数: |
1072 次 |
| 最近记录: |