在Windows批处理文件中捕获响应

时间:2016-11-15 20:37:00

标签: git batch-file

我正在制作一个小批量文件来从git中提取。我使用以下内容:

call git pull origin master

但是当命令的响应为Already up-to-date.

时,希望批处理文件的其余部分停止运行

我该怎么做?

1 个答案:

答案 0 :(得分:2)

将其传输到findstr,然后检查错误级别

git pull | findstr /C:"Already up-to-date"

IF %errorlevel%==0 GOTO:EOF

echo Continuing ....

解释findstrerrorlevel http://ss64.com/nt/findstr.html的关系说:

FINDSTR will set %ERRORLEVEL% as follows:

0 (False) a match is found in at least one line of at least one file.
1 (True) if a match is not found in any line of any file, (or if the file is not found at all).
2 Wrong syntax 
An invalid switch will only print an error message in error stream.