Pritiranjan Mishra
Pritiranjan Mishra

Reputation: 103

How to call .exe file with arguments from node.js

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();

Upvotes: 0

Views: 5995

Answers (1)

hbamithkumara
hbamithkumara

Reputation: 2534

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

Upvotes: 3

Related Questions