17
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

posted at

updated at

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

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

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
17
Help us understand the problem. What are the problem?