如何使用来自 node.js 的参数调用 .exe 文件

我正在尝试使用 3 个参数从 node.js 调用 exe 文件。得到错误为


errno: 'ENOENT'

code: 'ENOENT'

我正在使用 64 位 windows 10 系统。这是我目前使用的代码


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


烙印99
浏览 330回答 1
1回答

慕勒3428872

您需要将文件名和参数分开。语法:child_process.execFile(file[, args][, options][, callback])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();在以下示例中,我使用 javac.exe 编译 Main.java。这里文件名是 javac.exe 路径,Main.java 是参数。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript