Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start-Process gives error

Here's the code

$tool =  "E:\Experiments\Popup\latest\xperf.exe"
$toolOutput =  "XPerfOutput.log"
$toolError = "XPerfError.log"
$command = "-stop"


$x = Start-Process -FilePath $tool -ArgumentList $command -RedirectStandardOutput $toolOutput -RedirectStandardError $toolError -WindowStyle Hidden -PassThru -Wait  

And Here's there error:

Start-Process : Parameter set cannot be resolved using the specified named parameters. At E:\Experiments\Popup\asd.ps1:9 char:1
+ Start-Process -FilePath $tool -ArgumentList $command -RedirectStandardOutput $toolOutput RedirectStandardError $toolError -WindowStyle Hidden
-PassThru -Wait
+ ~~~~~~~~~~~~~
+ CategoryInfo          : InvalidArgument: (:) [Start-Process], ParameterBindingException
+ FullyQualifiedErrorId : AmbiguousParameterSet,Microsoft.PowerShell.Commands.StartProcessCommand

I want to run the process in a hidden window, wait for it to return and get the error, output and exit code.

like image 503
R.D Avatar asked Feb 02 '23 23:02

R.D


1 Answers

According to the documentation for Start-Process, the combination of the redirection parameters (RedirectStandardOutput and RedirectStandardError) and the WindowStyle parameter is invalid since they exist in separate parameter sets.

This means that they cannot be used together. This is why you're receiving that particular error.

like image 73
Scott Saad Avatar answered Feb 12 '23 13:02

Scott Saad