1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Windowsバッチ(.bat)学習メモ 他batからの戻り値取得

Posted at
呼び出し元.bat
@echo off

set callTargetBat="呼び出し対象.bat"

for /f "usebackq" %%a in ('call %callTargetBat% arg1 "arg2" arg3') do (
    set returnVal=%%a
)

echo %returnVal%
呼び出し対象.bat
@echo off

setlocal
set finalVal=%1_%2_%3
echo %finalVal%
endlocal
結果
returnVal is
arg1_"arg2"_arg3

※呼び出し対象の標準出力を拾っているだけのため、他のechoが存在していたり、エラーメッセージが出たり、echo offを設定していなかったりすると、意図しないものが拾われてしまうので注意。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?