2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Go言語で、外部エディタを起動する

Last updated at Posted at 2016-11-12

やったこと

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

参考

2
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?