Itay Gil
Itay Gil

Reputation: 251

enter command output to variable in batch

I need to check in my batch script what python --version response is.

For that, I want to enter to a variable the output of the python --version commands :

set /u cmd=python --version
%cmd%

What should i do next ?

Upvotes: 1

Views: 216

Answers (1)

user7818749
user7818749

Reputation:

Use a for loop.

for /f "delims=!" %%i in ('python --version') do set VAR=%%i
echo %VAR%

I changed %cmd% to %VAR% as it is a bad idea to set variable names that resemble system commands such as cmd which is in fact cmd.exe

Upvotes: 2

Related Questions