Reputation: 949
I want to execute one command and assign it's value to a variable within a batch file.
We know that running hostname command on a windows command prompt gives the PC name. I want to use hostname command and assign it's value to a variable within a batch file.
After googling about it, I've tried using below methods, none of these seem to work:
set CONTROLLER=hostname
set CONTROLLER=%hostname%
set CONTROLLER=%%hostname%%
set CONTROLLER=!hostname!
Kindly advise.
Upvotes: 4
Views: 1787
Reputation: 80
We can easily get the hostname/computer name through below command
set host=%COMPUTERNAME%
echo %host%
Upvotes: 4
Reputation: 304
Try Using
@echo off
for /f "delims=" %%a in ('hostname') do @set HOST=%%a
echo %HOST%
PAUSE
Where HOST is your variable and in place of 'hostname' you can use any other command you like as well.
Upvotes: 1