如何抑制PowerShell中的标准错误输出? [英] How do I suppress standard error output in PowerShell?
问题描述
在自动执行某些SVN任务的PowerShell脚本中,我具有以下功能:
In a PowerShell script automating some SVN tasks I have the following function:
function SvnUrlExists($url)
{
svn info $url | out-null 2>&1
return $?
}
由于这明确地测试了是否存在某些SVN存储库URL,所以我对任何错误输出完全不感兴趣.但是,尽管我在PowerShell中发现了有关重定向stderr
的所有建议,建议将2>&1
重定向到stdout
,但 这仍然会输出错误消息 :
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?
推荐答案
以防其他人谷歌搜索与我相似的条款:
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
这就像一个护身符.
这篇关于如何抑制PowerShell中的标准错误输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!