7
5

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.

コマンドを実行して出力を処理する exec.Command()

Last updated at Posted at 2014-11-20
import "os/exec"

しておいて、

cmd := exec.Command("ls", "-l", ".")
output, err := cmd.Output()
if err != nil {
  log.Fatal(err)
}
println(string(output))
  • func (c *Cmd) Run() error - コマンドの終了を待つ

  • func (c *Cmd) Start() error - コマンドの終了を待たない

  • func (c *Cmd) Output() ([]byte, error) - 標準出力を[]byteにまとめて返す

  • func (c *Cmd) CombinedOutput() ([]byte, error) - 標準出力と標準エラー出力を[]byteにまとめて返す

7
5
2

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
7
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?