LoginSignup
0
0

More than 1 year has passed since last update.

go言語でWindowsをシャットダウンする

Posted at

結論

exec.Command を利用する

exec.Command(`shutdown`, "-s", "-t", "0").Start()

注意点

exec.Command だけではなく、以下を呼び出す必要がある(でなければ、コマンドは実行されない)

  1. Output() // stdout
  2. CombinedOutput() // stdout, stderr
  3. Start() // プロセスの終了を待たない
  4. Run() // プロセスの終了を待つ

引数について

exec.Command(`shutdown`, "-s", "-t 0").Start()

では動かない。
どうやら、スペースで区切られたものをすべて切り出して引数にする必要があるらしい。("-t 0" -> "-t", "0" にしないと動かない)

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