Assign output of a program to a variable using a MS batch file
问题 I need to assign the output of a program to a variable using a MS batch file. So in GNU Bash shell I would use VAR=$(application arg0 arg1) . I need a similar behavior in Windows using a batch file. Something like set VAR=application arg0 arg1 . 回答1: One way is: application arg0 arg1 > temp.txt set /p VAR=<temp.txt Another is: for /f %%i in ('application arg0 arg1') do set VAR=%%i Note that the first % in %%i is used to escape the % after it and is needed when using the above code in a batch