LoginSignup
2
2

More than 5 years have passed since last update.

hubotで外部コマンドを使う - 覚え書き

Last updated at Posted at 2015-11-16

hubotで外部コマンドを使いたい。外部コマンドにパイプで入力値を流しこみたい。CoffeeScriptを書くのははじめてなのであまり良い方法ではないかもしれない。覚え書きだ。

例として標準出力の1行目を逆にしたものを出力とする外部コマンド

% ghc -e 'interact $ reverse . head . lines'

を使っている。この部分を自分の好きな外部コマンドに置き換えれば良い。

reverse.coffee
spawn = require('child_process').spawn

module.exports = (robot) -> robot.hear /reverse/i, (msg) ->
        echo = spawn 'echo', [msg.message]
        reverse = spawn 'ghc', ['-e', 'interact $ reverse . head . lines']
        echo.stdout.on 'data', (data) -> reverse.stdin.write(data)
        reverse.stdout.on 'data', (data) -> msg.send data.toString()
2
2
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
2
2