如何在.bat批处理文件中执行此操作:
if ("c:\program files\visualsvn server\bin\svnlook.exe" log -r2 d:\repositories\myrepo | findstr "~~DEPLOY~~" )
(
#dosomething
)
else
(
#dosomethingelse
)
现在我收到错误此时此日志意外。
答案 0 :(得分:2)
使用&&和||根据前一个命令的成功或失败有条件地执行命令
"c:\program files\visualsvn server\bin\svnlook.exe" log -r2 d:\repositories\myrepo | findstr "~~DEPLOY~~" >nul && (
#do_Something_If_Success
) || (
#do_Something_Else_If_Failure
)
答案 1 :(得分:1)
请改为尝试:
setlocal enabledelayedexpansion
set found_deploy=0
for /f 'eol=; tokens=1 delims=' %%c in ('"c:\program files\visualsvnserver\bin\svnlook.exe" log -r2 d:\repositories\myrepo ^| findstr "~~DEPLOY~~"') do (
set found_deploy=1
)
if "!found_deploy!"=="1" (
@REM::do_something_based_on_finding_deploy
) else (
@REM::do_something_based_on_not_finding_deploy
)
答案 2 :(得分:1)
这是前两者之间的中间点:
"c:\program files\visualsvn server\bin\svnlook.exe" log -r2 d:\repositories\myrepo | findstr "~~DEPLOY~~" >nul
if errorlevel 1 (
echo Deploy not found
) else (
echo Deploy found
)