Hubotで外部コマンドを実行する
Node.jsで外部コマンドを実行するために、Child Processを利用する。
Child Process | Node.js v6.5.0 Documentation
const exec = require('child_process').exec;
exec('cat *.js bad_file | wc -l', (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
return;
}
console.log(`stdout: ${stdout}`);
console.log(`stderr: ${stderr}`);
});Hubotの例
child_process = require 'child_process'
module.exports = (robot) ->
robot.hear /ruby/i, (res) ->
child_process.exec "ruby -v", (error, stdout, stderr) ->
if !error
output = stdout+''
res.send output
else
res.send 'error'参考
Related contents
TECH
2016.08.28
TECH
2016.08.27
TECH
2016.08.24
TECH
2016.05.11
TECH
2016.02.20
TECH
2016.02.07
TECH
2016.02.07
TECH
2016.02.06