Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 368
Muhammad Rehan Saeed Avatar asked Nov 03 '25 11:11

Muhammad Rehan Saeed


1 Answers

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
like image 104
Ansgar Wiechers Avatar answered Nov 05 '25 01:11

Ansgar Wiechers