How do I suppress standard error output in PowerShell?

sbi picture sbi · Aug 15, 2012 · Viewed 39.4k times · Source

In a PowerShell script automating some SVN tasks I have the following function:

function SvnUrlExists($url)
{
  svn info $url | out-null 2>&1
  return $?
}

Since this explicitly tests whether some SVN repository URL exists, I am not interested at all in any error output. However, despite everything I found about redirecting stderr in PowerShell suggesting 2>&1 to redirect it to stdout, this still outputs an error message:

svn: warning: W170000: URL 'blahblah' non-existent in revision 26762
svn: E200009: Could not display info for all targets because some targets don't exist

Unfortunately, this severely messes up the output of my script.

What am I doing wrong, and how should I suppress this error output?

Answer

sbi picture sbi · Aug 15, 2012

Just in case someone else googles for similar terms as I did:

After I have been banging my forehead against this for hours, of course I found the solution within minutes after posting the question here:

svn info $url 2>&1 | out-null

This works like a charm.