0

我制作了一个批处理脚本,其中包括使用以下命令将我们的 DEV 分支合并到我们的 TEST 分支:

tf merge $/Proj/Dev $/Proj/Test /recursive >nul

此命令始终触发以下输出:

TF401190: The local workspace [workspace];[name] has 110500 items in it, which exceeds the recommended limit of 100000 items. 
To improve performance, either reduce the number of items in the workspace, or convert the workspace to a server workspace.

我知道我可以通过在命令末尾添加“2>&1”来避免所有错误/输出,如下所示:

tf merge $/Proj/Dev $/Proj/Test /recursive >nul 2>&1

理想情况下,我只想忽略/抑制 TF401190 错误。我觉得必须有一种方法可以做到这一点,即使这意味着在允许打印之前检查输出是否有特定的标记/字符串。我对命令行和批处理脚本还是很陌生。任何帮助将不胜感激!谢谢。

注意:我对解决错误本身的解决方案不感兴趣。这个问题只关心如何抑制任何特定的错误。

4

2 回答 2

1

在 bash shell 中,您可以过滤掉特定的错误,如下所示:

ls /nothere

ls: cannot access /nothere: No such file or directory

要抑制该特定错误消息:

ls /nothere 2>&1 | grep -v 'No such file'

(错误消息被抑制)

检查其他错误消息是否通过:

ls /root 2>&1 | grep -v 'No such file'
ls: cannot open directory /root: Permission denied

(其他错误消息通过正常)

于 2015-07-09T18:47:22.780 回答
0

这个问题的答案是对Is there a way to redirect only stderr to stdout (不将两者结合起来)以便可以通过管道传输到其他程序的扩展?

您需要以仅输出错误的方式重定向 stderr 和 stdout,并将错误消息通过 FIND 或 FINDSTR 命令过滤掉您不想要的消息。

tf merge $/Proj/Dev $/Proj/Test /recursive 2>&1 >nul | findstr /b ^
  /c:"TF401190: The local workspace " ^
  /c:"To improve performance, either reduce the number of items in the workspace, or convert the workspace to a server workspace."

我使用了续行来使代码更易于阅读。

于 2015-07-09T22:11:29.707 回答