【发布时间】:2018-09-27 02:44:30
【问题描述】:
我正在使用 heroku API 制作一个 web-app-deployment-platform。 为了使用 heroku API,它需要使用 heroku CLI 登录。我让 docker image 安装了 heroku CLI 所以,我正在尝试使用 nodejs 在 docker 上登录 heroku。
Heroku login 是在 heroku CLI 中登录 heroku 的命令。它需要连续的输入。 (电子邮件和密码)
heroku login
> Email: (you need to input email then password)
但是我下面的代码不起作用。
var spawn = require('child_process').spawn;
login: function(req, callback) {
var result = "";
var heroku_login = spawn('docker', ['exec', '-it', 'my container name', 'heroku', 'login']);
heroku_login.stdin.setEncoding('utf-8');
heroku_login.stdin.write(req.heroku_email);
heroku_login.stdin.write(req.heroku_pwd);
heroku_login.stdout.on('data', function(data) {
result += data.toString();
console.log(result);
}
heroku_login.stdout.on('end', function() {
callback(null, result);
}
}
对不起我的英语水平。如果你不明白我的话,请给我评论。
【问题讨论】:
-
我也有类似的问题。似乎还没有答案;但如果你自己解决了这个问题;你能发布答案吗?
-
@Neil 我已经通过调用 http api 解决了。
exec('curl -nX GET https://api.heroku.com/apps -H "Accept: application/vnd.heroku+json; version=3" -H "Authorization: Bearer ' + api_key + '"' , function(err, stdout, stderr) { ...` -
酷。我最终通过在
child.stdout.on("data", (data) => {...中检查data然后在该检查中调用child.stdin.write(...)解决了我的问题。 -
@Neil 讨厌唤醒一匹早已死去的马再次被打败,但你介意把它放在一个正式的答案中,这样它就不会过目了吗?当它隐藏在评论中时,很容易忽略解决方案,对于我们这些通过谷歌搜索遇到十几个或更多 SO 问题的人来说:D
标签: node.js docker heroku spawn