title: Run cmd.exe from PowerShell
body: <p>I am trying to run some unit tests using PowerShell. I have a command that (sort of) works:</p>
  
  <pre><code>$output = &amp; $vsTestPath $TestAssembly $logger $TestCaseFilter 2&gt;&amp;1
  </code></pre>
  
  <p>The problem with this is that the standard out and standard error streams don't come out in the right order - they get mixed up. One solution to this (from <a href="http://chuchuva.com/pavel/2010/03/how-to-redirect-output-of-console-program-to-a-file-in-powershell/" rel="nofollow noreferrer">here</a>) is to use cmd.exe, but I cannot get this to work. I feel like I've tried everything I can think of.</p>
  
  <p>Here's what I have:</p>
  
  <pre><code>$vsTestPath = "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe"
  $TestAssembly = "C:\IntegrationTesting\Test Application\Ads.Slms.IntegrationTesting.Web.Smartfill.dll"
  $output = &amp; cmd.exe /c $vsTestPath $TestAssembly 2`&gt;`&amp;1
  </code></pre>
  
  <p>This last line does not work. Wierdly, if I just have</p>
  
  <pre><code>$output = &amp; cmd.exe /c $vsTestPath 2`&gt;`&amp;1
  </code></pre>
  
  <p>Then this runs, but of course it's no use to me. It's the second parameter that's the problem. Other things I've tried. How can I get this to run?</p>
  
  <pre><code>$output = &amp; cmd.exe /c $vsTestPath $TestAssembly 2`&gt;`&amp;1
  $output = &amp; cmd.exe /c $vsTestPath,$TestAssembly 2`&gt;`&amp;1
  $output = &amp; cmd.exe /c "$vsTestPath" $TestAssembly 2`&gt;`&amp;1
  $output = &amp; cmd.exe /c """$vsTestPath""" $TestAssembly 2`&gt;`&amp;1
  $output = &amp; cmd.exe /c "$vsTestPath" "$TestAssembly" 2`&gt;`&amp;1
  $output = &amp; cmd.exe /c """$vsTestPath""" """$TestAssembly""" 2`&gt;`&amp;1
  </code></pre>