4

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

1 Answer 1

7

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
Sign up to request clarification or add additional context in comments.

2 Comments

You can read more on this from about_redirection
Windows' own sc.exe throws error to STDOUT

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.