LoginSignup
4
4

More than 5 years have passed since last update.

プログラム実行中に外部エディタを使って入力させる方法

Last updated at Posted at 2013-01-28

SVNやGitで外部エディタを使ってコミットメッセージを入力させるのと同じことを、rubyで行いたいと思った場合、以下のようにすれば一応出来る。

require 'tempfile'

abort "External variable HOGE_EDITOR isn't set!" unless editor = ENV['HOGE_EDITOR']
tmp = Tempfile.new('deleted_soon')
system(editor + " " + tmp.path)
message = File.open(tmp.path).readlines
tmp.unlink # delete the temp file

puts message
4
4
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
4
4