title: Run a external program with parameters and wait for it to end in Powershell
body: <p>Actually, I've found so many solutions to this question, but none works.
  The program I'd like to run in Powershell is Reaper - a Digital Audio Workstation, and I'm going to use its command line tool for batch-processing audio files within a PS script. The code related to Reaper is as below:  </p>
  
  <pre><code>reaper -batchconvert $output_path\audio\Reaper_filelist.txt
  </code></pre>
  
  <p>I'm going to use the <code>Start-Process</code> with <code>-wait</code> parameter to allow my script to wait for it to end then go on to the next line of code which is a <code>Rename-Item</code> function.  </p>
  
  <pre><code>ls $processed_audio_path | Rename-Item -NewName {$_.name.Replace("- ", "")}
  </code></pre>
  
  <p>If PS doesn't wait for the process to finish, then the next line would throw an error, something like "no such file was found in the directory".</p>
  
  <p>The suggestions I've found are <a href="https://stackoverflow.com/questions/1741490/how-to-tell-powershell-to-wait-for-each-command-to-end-before-starting-the-next">here</a>, <a href="https://stackoverflow.com/questions/25187048/run-executable-from-powershell-script-with-parameters">here</a>, and <a href="https://stackoverflow.com/questions/41147003/how-to-call-an-exe-from-powershell-with-parameters">here</a>. But none of those work. The problem is that Reaper doesn't accept the argument to be added separately as:</p>
  
  <pre><code>$exe = "reaper"
  $arguments = "-batchconvert $output_path\audio\Reaper_filelist.txt"
  Start-Process -filepath $exe -argumentlist $arguments -wait
  </code></pre>
  
  <p>or:</p>
  
  <pre><code>Start-Process -filepath reaper -argumentlist "-batchconvert $output_path\audio\Reaper_filelist.txt" -Wait
  </code></pre>
  
  <p>or:</p>
  
  <pre><code>Start-Process -filepath reaper -argumentlist @("-batchconvert", "$output_path\audio\Reaper_filelist.txt") -Wait
  </code></pre>
  
  <p>It can only work without a problem as a whole block like the first code line above.
  So what can I do now? </p>