Search code examples
powershellerror-handlingexecutablepowershell-cmdlet

Suppressing Powershell Errors When Calling External Executables


I have a PowerShell script that is calling an external executable and I want to suppress any error that comes from it. How can this be achieved. With PowerShell cmdlets, I can use the standard -ErrorAction argument to SilentlyContinue, however this is an external executable:

someExe --argument

Solution

  • The error output of external commands goes to the error stream (provided the command is writing error messages to STDERR), so you just need to redirect that stream to suppress the message:

    someExe --argument 2>$null
    

    If the command writes to STDOUT instead of STDERR (unusual behavior, but not unheard of) you may need to redirect the success output stream instead:

    someExe --argument >$null