我如何将git的STDERR输出通过管道传递给findstr以获取实际结果?

时间:2018-06-21 20:09:04

标签: git batch-file cmd

我正在尝试让git show-branch告诉我使用Window 7 cmd是否存在分支,为此,我已经设置了.bat文件,并且试图过滤git命令的输出,知道git输出到STDERR。

for /f %%L in ('git show-branch remotes/origin/develop-7.x 2^> nul ^| findstr /b "fatal"') do set VAR=%%L echo %VAR%

我的git命令输出是这样的: fatal: bad sha1 reference remotes/origin/develop-7.x

问题是我无法通过STDERR传递findstr和VAR给我一些东西。

如果我将&1添加到2^>&1 1>nul,则会收到错误消息& was unexpected at this time

1 个答案:

答案 0 :(得分:1)

2^>^&1-和号也必须转义