title: Explicitly calling program create new window and doesn't work
body: <p>I need to obtain the version of Maven's binary but using an explicit call to the program bring up a secondary windows and doesn't work.</p>
  
  <p>In this case, it spawns a new window and returns nothing:</p>
  
  <pre><code># spawns a new window with an error
  # wanted to be more explicit in my call to the program
  Write-Host "Maven..."
  $x = &amp; 'C:\path\to\maven\bin\mvn' '-version' 2&gt;&amp;1
  Write-Host "out: "$x
  </code></pre>
  
  <p>In this case, it works as intended, but I have to assume the environment variable is configured:</p>
  
  <pre><code># works as intended
  # implies path is set
  Write-Host "Maven..."
  $x = &amp; 'mvn' '-version' 2&gt;&amp;1
  Write-Host "out: "$x
  </code></pre>
  
  <p>Any reasons why this is happening? Ideally, I'd like the first method to work.</p>
  
  <p><strong>Edit #1</strong></p>
  
  <p>Been trying the following, using Start-Process (from <a href="https://stackoverflow.com/questions/8761888/capturing-standard-out-and-error-with-start-process">Capturing standard out and error with Start-Process</a>)</p>
  
  <pre><code>Try {
      $pinfo = New-Object System.Diagnostics.ProcessStartInfo
      $pinfo.FileName = "C:\path\to\maven\bin\mvn"
      $pinfo.RedirectStandardError = $true
      $pinfo.RedirectStandardOutput = $true
      $pinfo.UseShellExecute = $false
      $pinfo.Arguments = "-version"
      $p = New-Object System.Diagnostics.Process
      $p.StartInfo = $pinfo
      $p.Start() | Out-Null
      $stdout = $p.StandardOutput.ReadToEnd()
      #$stderr = $p.StandardError.ReadToEnd()
      #$exitCode = $p.ExitCode  
      $p.WaitForExit()
  
      Write-host "out: "$stdout
  }
  Catch {
      Write-Host  $_.Exception.Message
  }
  </code></pre>
  
  <p>I get this error:</p>
  
  <blockquote>
    <p>Exception calling "Start" with "0" argument(s): "The specified
    executable is not a valid application for this OS platfor m."</p>
  </blockquote>