0

I have an exe and I want to run it from node.js, and pass an argument, except that it doesn't work..

var exec = require('child_process').execFile;
const fs = require('fs');

try {
  if (fs.existsSync("./program/bin/Release/program.exe")) {
    console.log("Exists")
  } else {
    console.log("Not Exists")
  }
} catch(err) {
  console.log(err)
}

setTimeout(function() {
    exec('./program/bin/Release/program.exe manual', function(err, data) {  
        console.log(err)
        console.log(data.toString());                       
    });  
}, 0);

It definitely exists as it prints exists, and I can run it from a cmd prompt giving manual as an argument. But through node.js it is not working. It comes back with

Error: spawn ./program/bin/Release/program.exe manual ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:264:19)
    at onErrorNT (internal/child_process.js:456:16)
    at processTicksAndRejections (internal/process/task_queues.js:80:21) {
  errno: 'ENOENT',
  code: 'ENOENT',
  syscall: 'spawn ./program/bin/Release/program.exe manual',
  path: './program/bin/Release/program.exe manual',
  spawnargs: [],
  cmd: './program/bin/Release/program.exe manual'
}

Does anyone know?

Thanks

1

1 Answer 1

1

Arguments should be passed as an array of strings as the second argument, like so:

exec('./program/bin/Release/program.exe', ['manual'], function(err, data) {  
    console.log(err)
    console.log(data.toString());                       
});  

https://nodejs.org/api/child_process.html#child_process_child_process_execfile_file_args_options_callback

Sign up to request clarification or add additional context in comments.

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.