I'm using node.js in my server side. Now I wanna run some binary file compiled 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 compiled 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!
var 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);
}
});
sys module is is deprecated. util took it's place. Why bother though, just use console.log() or process.stdout.write()The below code snippet from codegrepper.com 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}`);
});