I'm using node.js in my server side. Now I wanna run some binary file piled from a .c code, how to do that?
I've already tried
var obj = new ActiveXObject("WwScript.Shell");
obj.run("myBinary");
But doesn't work... Thanks a lot!
I'm using node.js in my server side. Now I wanna run some binary file piled from a .c code, how to do that?
I've already tried
var obj = new ActiveXObject("WwScript.Shell");
obj.run("myBinary");
But doesn't work... Thanks a lot!
Share Improve this question asked Feb 12, 2012 at 5:07 Yuming CaoYuming Cao 9551 gold badge11 silver badges22 bronze badges 1- I think you're looking for child_process.exec. – Jared Farrish Commented Feb 12, 2012 at 5:13
2 Answers
Reset to default 8var sys = require('sys')
var exec = require('child_process').exec;
exec("/path/to/your/Binary", function(error, stdout, stderr) { sys.puts(stdout) });
Update:
It seems that sys
module is is deprecated, use util
instead as @loganfsmyth mentioned.
var exec = require('child_process').exec,
child;
child = exec('/path/to/your/Binary',
function (error, stdout, stderr) {
console.log('stdout:', stdout);
console.log('stderr:', stderr);
if (error !== null) {
console.log('exec error:', error);
}
});
The below code snippet from codegrepper. worked for me :)
const { exec } = require("child_process");
exec("ls -la", (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
return;
}
if (stderr) {
console.log(`stderr: ${stderr}`);
return;
}
console.log(`stdout: ${stdout}`);
});