Search code examples
javascriptnode.jswebkitexenode-webkit

Javascript - How to execute the executable file located in C:\?


With NW i have following code. Which is executing Java or other scripts. But not able to run any location path for example the following is failing.

var exec = require('child_process').exec;
function voidrun(input){
  run_void = exec(input, function (error, stdout, stderr) { 
    sys.print('stdout: ' + stdout); 
    sys.print('stderr: ' + stderr); 
    if (error !== null) { 
      console.log('exec error: ' + error);
    }
  }); 

  run_void.on('exit', function(code) {
      console.log('Child process exited '+ code);
  });  
}

function boot() {
    runme('C:\\run\splashscreen.exe');  
}

Solution

  • Try this:

    var exec = require('child_process').exec;
    
    var cmd = 'executable.exe parameter1 parameter2';
    var path = 'c:\\path';
    var child = exec(
        cmd, {
            cwd: path
        },
        function(error, stdout, stderr) {
            if (error === null) {
                console.log('success');
            } else {
                console.log('error');
            }
        }
    );