2

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!

1

2 Answers 2

8
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);
    }
});
Sign up to request clarification or add additional context in comments.

1 Comment

The sys module is is deprecated. util took it's place. Why bother though, just use console.log() or process.stdout.write()
0

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}`);
    });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.