简体   繁体   English

Node.JS:execFile ENOENT

[英]Node.JS: execFile ENOENT

I've tried to execute *.exe file, but got: 我尝试执行*.exe文件,但得到:

exec error: { Error: spawn ${__dirname}/install.exe ENOENT

Code: 码:

var execFile = require('child_process').execFile
execFile('${__dirname}/install.exe', function(error, stderr) {
   console.log('stderr: ', __dirname);
   if (error !== null) {
       console.log('exec error: ', error);
   }
  });

Also tried: '${__dirname}\\install.exe' , './install.exe' , 'D:\\install.exe' 还尝试过: '${__dirname}\\install.exe''./install.exe' '${__dirname}\\install.exe' './install.exe''D:\\install.exe'

@FelixKling has the right advice; @FelixKling有正确的建议; variables don't work unless you create your string with back-ticks. 除非您使用反引号创建字符串,否则变量将不起作用。 Additionally, it's a good idea to use the path module to resolve file paths: 此外,最好使用path模块来解析文件路径:

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

var exePath = path.resolve(__dirname, './install.exe');
execFile(exePath, function(error, stderr) {
   console.log('stderr: ', __dirname);
   if (error !== null) {
       console.log('exec error: ', error);
   }
});

Edit : 编辑

This is for your original question, about ENOENT ; 这是关于ENOENT原始问题; for your second about UNKNOWN errors, the cause can vary. 对于UNKNOWN错误,您的原因可能有所不同。 It sounds like it might be a permissions issue since the executable needs to elevate to administrator permissions. 听起来可能是权限问题,因为可执行文件需要提升为管理员权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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