简体   繁体   中英

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

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.

例子

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM