LoginSignup
15
17

More than 5 years have passed since last update.

Hubot で外部コマンドを実行する

Last updated at Posted at 2014-09-10

Hubot で外部コマンドを実行する

概要

Hubot で外部コマンドを実行します。
検証はWindows環境で行います。

node.js の child_process を利用します。

サンプルコード

Windows の date コマンドの結果を取得してみます

# Description
#   Output external command
#
# Dependencies:
#   None
#
# Configuration:
#   None
child_process = require 'child_process'

module.exports = (robot) ->
  say = (message) ->
    user = {
      room :
        id : 6 # Other
    }

    robot.send user, message

  robot.respond /date/i, (msg) ->
    child_process.exec "date \/T", (error, stdout, stderr) ->
      if !error
        output = stdout+''
        say output
      else
        say "error"

出力

shell adapter で確認

Hubot> hubot date
Hubot> 2014/09/10

補足

今のところ、 npm で公開したりする予定はないので適当にGitHubに突っ込んでおきます。
https://github.com/tbpgr/hubot_scripts

15
17
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
17