Wednesday 15 September 2010

spawn - (Node.js) How to store stdout.pipe into a variable? -



spawn - (Node.js) How to store stdout.pipe into a variable? -

i want free -m (linux shell command) , store result variable using source code below:

var spawn = require('child_process').spawn, command = spawn('free', ['-m']); command.stdout.pipe(process.stdout);

is there way store process.stdout in variable, please me suggestions

this simple child_process.exec:

var kid = require("child_process"); var freeout; child.exec("free", ["-m"], function (error, stdout, stderr) { if (error) { console.error(error, stderr); return; } //stdout , stderr available here freeout = stdout; process.stdout.write(stdout); }); //note. not utilize freeout here. exec async. can utilize in callback

node.js spawn node.js-stream

No comments:

Post a Comment