やったこと
Go言語でちょっとしたコマンドラインツールを作ろうと思っていて、外部エディタを実行中のターミナル内で立ち上げる方法が知りたかったのでメモ。
コマンドの入出力を標準入出力に指定するのがポイント。
vim.go
package main
import (
"os"
"os/exec"
)
func main(){
cmd := exec.Command("vim", "/tmp/hoge")
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Run()
}
下記で実行すると、実行中にVimが立ち上がり、編集できる。
go run vim.go