title: How to assign command value to variable in batch
body: <p>I want to execute one command and assign it's value to a variable within a batch file. </p>
  
  <p>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.</p>
  
  <p>After googling about it, I've tried using below methods, none of these seem to work:</p>
  
  <pre><code>set CONTROLLER=hostname
  set CONTROLLER=%hostname%
  set CONTROLLER=%%hostname%%
  set CONTROLLER=!hostname!
  </code></pre>
  
  <p>Kindly advise.</p>