I'm starting a new process like this:
$p = Start-Process -FilePath $pathToExe -ArgumentList $argumentList -NoNewWindow -PassThru -Wait
if ($p.ExitCode -ne 0)
{
Write-Host = "Failed..."
return
}
And my executable prints a lot to console. Is is possible to not show output from my exe?
I tried to add -RedirectStandardOutput $null
flag but it didn't work because RedirectStandardOutput
doesn't accept null
. I also tried to add | Out-Null
to the Start-Process
function call - didn't work. Is it possible to hide output of the exe that I call in Start-Process
?
To redirect the error stream to null, you would apply 2>$null to the cmdlet that's throwing the error.
You're invoking the executable synchronously (-Wait
) and in the same window (-NoNewWindow
).
You don't need Start-Process
for this kind of execution at all - simply invoke the executable directly, using &
, the call operator, which allows you to:
$LASTEXITCODE
for the exit code& $pathToExe $argumentList *> $null
if ($LASTEXITCODE -ne 0) {
Write-Warning "Failed..."
return
}
If you still want to use Start-Process
, see sastanin's helpful answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With