Powershell – How to suppress standard error output in PowerShell

io-redirectionpowershellsvn

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?

Best Answer

If you want to suppress only standard error, use:

svn info $url 2>$null