admin管理员组文章数量:1406926
I've tried to execute *.exe
file, but got:
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'
I've tried to execute *.exe
file, but got:
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'
-
1
Do you mean to use template literals? You have to use backticks:
`${__dirname}/install.exe`
.'${__dirname}/install.exe'
creates a string that literally contains the character sequence${__dirname}
. – Felix Kling Commented Jun 19, 2016 at 0:34 - @FelixKling, same again.. – Src Commented Jun 19, 2016 at 0:35
1 Answer
Reset to default 5@FelixKling has the right advice; 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:
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
; for your second about UNKNOWN
errors, the cause can vary. It sounds like it might be a permissions issue since the executable needs to elevate to administrator permissions.
本文标签: javascriptNodeJS execFile ENOENTStack Overflow
版权声明:本文标题:javascript - Node.JS: execFile ENOENT - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744983333a2635947.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论