Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6204941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:11:05+00:00 2026-05-24T05:11:05+00:00

I have a batch file that calls various commands, some of which will occasionally

  • 0

I have a batch file that calls various commands, some of which will occasionally fail due to network issues. Re-trying the command will usually result in success.

How can I re-try the commands automatically, up to a set number of tries?

Here is the some pseudo code that aims to explain further

call:try numTries "command and arguments"
exit

:try
REM execute %2, trying upto %1 times if it fails
%1 = %1 -1
eval %2
if %errorlevel%==0 exit \B
if %1 > 0 goto try
exit \B
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T05:11:06+00:00Added an answer on May 24, 2026 at 5:11 am

    The following script be be what you are looking for:

    CALL :try numTries "command and arguments"
    GOTO :EOF
    
    
    :try
    SET /A tries=%1
    
    :loop
    IF %tries% LEQ 0 GOTO return
    
    SET /A tries-=1
    EVAL %2 && (GOTO return) || (GOTO loop)
    
    :return
    EXIT /B
    

    The logic of the try sub-routine is this:

    1. Store the number of tries into a variable.

    2. Begin the loop. Check the tries variable. If 0 or less, return.

    3. Evaluate the command and arguments.

    4. If the returned value is ‘success’ (ERRORLEVEL is 0), return (from the try routine), otherwise go to #2 (the beginning of the loop).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a service that sometimes calls a batch file. The batch file takes
I have a batch file that will detect if the user has the .Net
I have a csv file that I will be regularly updating through a batch
Right now i have a batch job I wrote that calls another file and
I have a batch file that needs to be passed a parameter that will
I have a batch file that calls a Windows GUI application. The GUI app
I have a batch file which calls a Perl file which requires a input
I have a batch file that calls a vbscript file. I am trying to
Basically, let's say that I have a batch file that calls myapp1.exe and myapp1.exe
I have several batch files that I call from a parent batch file. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.