0

I am trying to call an exe file from the node.js with 3 parameters. Getting error as

errno: 'ENOENT'
code: 'ENOENT'

I am using 64 bit windows 10 system . Here is the code that i am using currently

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

var opt =function(){
      exec('file.EXE arg1 arg2 arg3', function(err, data) {  
        console.log(err)
        console.log(data.toString());                       
    });  
}
opt();
9
  • ENOENT indicates your file doesn't exist. Does calling it without any arguments result in different error? Commented Nov 22, 2019 at 10:38
  • It is in the same path @Subburaj Commented Nov 22, 2019 at 10:44
  • Without arguments it is opening the command prompt and asking the arguments one by one . I am able to run the .exe by the above code but something wrong with arguments . Now sure how to pass 3 parameters to it @Gavin Commented Nov 22, 2019 at 10:46
  • Where the file is and where the process is executed could be different. Try __dirname + '/file.exe' and see if that works? Commented Nov 22, 2019 at 10:46
  • Everything is in one directory for now @Gavin Commented Nov 22, 2019 at 10:48

1 Answer 1

3

You need to separate file name and arguments.

Syntax: child_process.execFile(file[, args][, options][, callback])

Node Doc

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

var opt = function(){
      exec('file.EXE', ["arg1", "arg2", "arg3"], function(err, data) {  
        console.log(err)
        console.log(data.toString());                       
    });  
}
opt();

In the following example, I'm compiling Main.java using javac.exe.

here file name is javac.exe path and Main.java is argument.

Example

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

3 Comments

It gives the same error "command line option syntax error". Anything because of my windows machine ?
Give me some time, I'll try on my system.
Hi @Pritiranjan Mishra, See the example above, It's working fine. Could you please check your configurations one more time.

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.