title: How to set command output as variable in batch
body: <p>First, I've googled and googled how to fix this problem, with no luck. I'm working on making a batch file to re-encode audio in a file to aac if it's ac-3 or ogg using ffmpeg. I know how to do the conversion with ffmpeg, just not how to automate it only if the audio matches a certain codec. To get the audio codec for the file, I have two different methods, one with ffprobe, and the other with MediaInfo.</p>
  
  <pre><code>MediaInfo --Inform="Audio;%%Format%%" "input.mkv"
  </code></pre>
  
  <p>or</p>
  
  <pre><code>ffprobe -v error -select_streams a:0 -show_entries stream=codec_name -of default=noprint_wrappers=1:nokey=1 "input.mkv"
  </code></pre>
  
  <p>However, my issue is with setting a variable from the command output. This is the code I've been trying, to no avail.</p>
  
  <pre><code>SETLOCAL
  
  for %%a in (*.mp4) do (
  
  MediaInfo --Inform="Audio;%%Format%%" "%%a"&gt;codec.txt
  
  SET /p codec=&lt;codec.txt
  
  DEL codec.txt
  
  ECHO %codec%
  
  )
  
  pause
  </code></pre>
  
  <p>Obviously, this is only a section of my goal, but this is the part I can't seem to get past. I have checked, by removing the "DEL codec.txt" part, that is in fact storing the correct output in the text file, but it's not importing it into the variable. Anyway I can set the output to a variable is fine, this is just the way I often found in my search.</p>
  
  <p>Any help is much appreciated.</p>