0

How do I do this in a .bat batch file:

 if ("c:\program files\visualsvn server\bin\svnlook.exe" log -r2 d:\repositories\myrepo | findstr "~~DEPLOY~~" )
    (
     #dosomething
    )
    else
    (
     #dosomethingelse
    )

now I receive an error log was unexpected at this time.

3 Answers 3

2

Use && and || to conditionally execute commands based on the success or failure of a previous command

"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
)
Sign up to request clarification or add additional context in comments.

Comments

1

Try this instead:

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
)

Comments

1

dbenham's answer assemble an IF-THEN-ELSE that is both advanced and criptic. kikuchiyo's one is unnecessarily complicated.

This is a medium point between the previous two:

"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
)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.