首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >使用node.js执行exe文件

使用node.js执行exe文件
EN

Stack Overflow用户
提问于 2013-11-04 13:49:09
回答 2查看 86K关注 0票数 48

我不知道如何在node.js中执行exe文件。这是我正在使用的代码。它不工作,也不打印任何东西。有没有可能使用命令行执行exe文件?

代码语言:javascript
复制
var fun = function() {
  console.log("rrrr");
  exec('CALL hai.exe', function(err, data) {

    console.log(err)
    console.log(data.toString());
  });
}
fun();
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-11-04 13:55:28

您可以在node.js中试用子进程模块的execFile函数

参考:http://nodejs.org/api/child_process.html#child_process_child_process_execfile_file_args_options_callback

你的代码应该类似于:

代码语言:javascript
复制
var exec = require('child_process').execFile;

var fun =function(){
   console.log("fun() start");
   exec('HelloJithin.exe', function(err, data) {  
        console.log(err)
        console.log(data.toString());                       
    });  
}
fun();
票数 66
EN

Stack Overflow用户

发布于 2018-12-16 21:56:07

如果要执行的exe位于其他目录中,并且您的exe与它所在的文件夹有一些依赖关系,请尝试在选项中设置cwd参数

代码语言:javascript
复制
var exec = require('child_process').execFile;
/**
 * Function to execute exe
 * @param {string} fileName The name of the executable file to run.
 * @param {string[]} params List of string arguments.
 * @param {string} path Current working directory of the child process.
 */
function execute(fileName, params, path) {
    let promise = new Promise((resolve, reject) => {
        exec(fileName, params, { cwd: path }, (err, data) => {
            if (err) reject(err);
            else resolve(data);
        });

    });
    return promise;
}

Docs

票数 11
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19762350

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档