Skip to content

Commit 2959d12

Browse files
committed
Fix for issue where incomplete data from the process was being JSON.parse'd causing error
Concat data as chunks, callback on ‘close’ instead
1 parent 44dd29f commit 2959d12

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,13 @@ R.prototype.call = function(_opts, _callback) {
2929
var opts = _.isFunction(_opts) ? {} : _opts;
3030
this.options.env.input = JSON.stringify([this.d, this.path, opts]);
3131
var child = child_process.spawn("Rscript", this.args, this.options);
32+
var body = "";
3233
child.stderr.on("data", callback);
3334
child.stdout.on("data", function(d) {
34-
callback(null, JSON.parse(d));
35+
body += d;
36+
});
37+
child.on("close", function(code) {
38+
callback(null, JSON.parse(body));
3539
});
3640
};
3741

0 commit comments

Comments
 (0)