I want to setup a site quickly, so I try express now. But I am pretty new to it. ;-( I need to invoke some executables in server part, and send to result back to browser. Following node.js shell command execution, now first step is done, but error happens in the second step.
here is my code:
/* GET home page. */
router.post('/', function (req, res) {
// Run C:\Windows\System32\netstat.exe -an
var foo = new run_cmd(
'netstat.exe', ['-an'],
function (me, buffer) {
me.stdout += buffer.toString()
},
function () {
res.send('netstat done~');
console.log(foo.stdout)
}
);
//console.log(req);
res.render('index', {
title: 'Express'
});
});
function run_cmd(cmd, args, cb, end) {
var spawn = require('child_process').spawn,
child = spawn(cmd, args),
me = this;
child.stdout.on('data', function (buffer) {
cb(me, buffer)
});
child.stdout.on('end', end);
}
Anyone could help me? thanks a lot.