exec

command
v0.0.0-...-0d282d9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 12, 2025 License: MIT Imports: 7 Imported by: 0

README

os/exec firststep

os/exec の使い方勉強。

開発環境起動

docker run -it --rm -v "$(pwd):/work" -p "0.0.0.0:5555:5555" --workdir /work golang:1.22.1-bookworm

プログラム一覧

which.go

引数で指定したコマンドが、パスの通った場所に存在するかを確認するコマンド

go run which.go ls
run_command.go

引数で指定したコマンドと引数を、 Go プログラム内から実行するサンプルプログラム

go run run_command.go tail -f ./run_command.go

Ctrl-CReceive SIGINT. を出力したあと tail コマンドも終了させる。

run_command_with_timeout.go

引数で指定したコマンドと引数を、 Go プログラム内から実行するサンプルプログラム キャンセル可能、かつ、5 秒でタイムアウト

go run run_command_with_timeout.go tail -f ./run_command.go

Ctrl-CCAMCEL. を出力したあと tail コマンドも終了させる。 また、 5 秒経過で TIMEOUT. を出力した後 tail コマンドも終了させる。

参照資料

Documentation

Overview

*

  • run_command.go *
  • 引数で指定したコマンドと引数を、 Go プログラム内から実行するサンプルプログラム。
  • Ctrl+C で実行したプログラムも終了させる。

*

  • run_command_with_timeout.go *
  • 引数で指定したコマンドと引数を、 Go プログラム内から実行するサンプルプログラム。
  • キャンセル可能、かつ、5 秒でタイムアウトする。

*

  • which.go *
  • 引数で指定したコマンドが、パスの通った場所に存在するかを確認するコマンド。
  • 存在する場合、そのパスを表示し、存在しない場合、終了コード 2 で終了する。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL