【Batch】バッチ ~ コマンド結果を変数に格納する ~

■ はじめに

小ネタ。
コマンド結果を変数に格納する

【1】構文

FOR /F %%i in (【コマンド】) DO @SET 【変数】=%%i

【2】サンプル

1)hostname

@echo off
FOR /F %%i in ('hostname') DO @SET result=%%i
echo %result%

参考文献

https://blog.treedown.net/entry/2020/04/02/010000
https://maku77.github.io/windows/io/set-command-result.html
https://www.javadrive.jp/command/bat/index10.html

関連記事

バッチ ~ 入門編 ~
https://dk521123.hatenablog.com/entry/2010/07/06/223905