{"id":331,"date":"2009-06-03T15:20:53","date_gmt":"2009-06-03T07:20:53","guid":{"rendered":"http:\/\/ramfree17.net\/capsule\/?p=331"},"modified":"2009-06-03T15:20:53","modified_gmt":"2009-06-03T07:20:53","slug":"looping-in-windows-batch-script","status":"publish","type":"post","link":"https:\/\/ramfree17.net\/capsule\/?p=331","title":{"rendered":"Looping in Windows batch script"},"content":{"rendered":"<p>We have a Rational Team Concert process that is executed by a scheduled task. The task tries to download the code from a server that unfortunately does act up from time to time during the middle of the download process. RTC currently does not have a retry function so the result needs to be manually checked and the process be restarted. Its not convenient so I created a batch loop in order to minimize the human interaction.<\/p>\n<p>Below is the base script that will retry the operation up to the figure specified in the <b>attempts<\/b> variable. The script uses the ping command to effect a delay between the retry attempts. For what it is worht I am releasing it under <a href=\"http:\/\/creativecommons.org\/licenses\/by\/3.0\/\">Creative Commons<\/a> just for the sake of attribution. \ud83d\ude42<\/p>\n<p><code><br \/>\nREM<br \/>\nREM Function: A sample batch script on how to retry a utility or another batch script that fails intermittently.<br \/>\nREM<br \/>\nREM Author: ramfree17<br \/>\nREM Email:  ramfree17@gmail.com<br \/>\nREM<br \/>\nREM License under: Creative Commons Attribution v3.0 Unported [http:\/\/creativecommons.org\/licenses\/by\/3.0\/]<br \/>\nREM<\/p>\n<p>@echo off<\/p>\n<p>set attempts=10<br \/>\nset counter=0<\/p>\n<p>call :load_func<\/p>\n<p>goto done<\/p>\n<p>:load_func<br \/>\nset \/a counter+=1<br \/>\necho Attempt %counter% out of %attempts%<\/p>\n<p>if %counter% GTR %attempts% goto :eof<\/p>\n<p>C:\\ibm\\sdp\\scmtools\\eclipse\\scm load \"TestWS\" -r \"https:\/\/someserver.com\/jazz\" -u \"testUser\" -d \"d:\\Workspace\\rtc\" -f  -P [password]<\/p>\n<p>REM Check the result. 0 is successful.<br \/>\nif %ERRORLEVEL% NEQ 0 ( ping -n 10 google.com<br \/>\ncall :load_func)<\/p>\n<p>goto :eof<\/p>\n<p>:error_section<br \/>\necho. ERROR: Unable to perform the action. Please see the log if any.<\/p>\n<p>:done<br \/>\necho exiting sample script.<\/p>\n<p><\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>We have a Rational Team Concert process that is executed by a scheduled task. The task tries to download the code from a server that unfortunately does act up from time to time during the middle of the download process. RTC currently does not have a retry function so the result needs to be manually [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18,6],"tags":[],"class_list":["post-331","post","type-post","status-publish","format-standard","hentry","category-non-floss","category-technology"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/ramfree17.net\/capsule\/index.php?rest_route=\/wp\/v2\/posts\/331","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ramfree17.net\/capsule\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ramfree17.net\/capsule\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ramfree17.net\/capsule\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ramfree17.net\/capsule\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=331"}],"version-history":[{"count":0,"href":"https:\/\/ramfree17.net\/capsule\/index.php?rest_route=\/wp\/v2\/posts\/331\/revisions"}],"wp:attachment":[{"href":"https:\/\/ramfree17.net\/capsule\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=331"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ramfree17.net\/capsule\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=331"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ramfree17.net\/capsule\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=331"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}