programming wait, in batch files

Sharky Forums


Results 1 to 8 of 8

Thread: programming wait, in batch files

Hybrid View

  1. #1
    Reef Shark Stasis's Avatar
    Join Date
    May 2001
    Location
    Wenatchee, WA, USA
    Posts
    373

    programming wait, in batch files

    One of our dns servers at work is messing up or something and I keep getting the external IP for intranet (since it can be accessed outside, but you cant double-NAT to it) and a simple fix for the mean time till I can figure out what the main problem is, is to bring up a command prompt and run

    Net stop "dns client"

    Net start "dns client"

    and that re-queries the dns (i think) and temporarly fixes the issue.

    It normally takes a few seconds for the first command to finish executing, so I want to have my batch file run the first, wait about 5seconds, then run the second. Ive researched a bit on the net and ive found alot of people saying to create a 2nd batch file and then call it within the first...id rather not do that, and id rather not use the pause command. Id like it to be automated, merely beacuse I want to see how to do it

    any ideas?

    im running winxp.

  2. #2
    Bearded Kirklander's Avatar
    Join Date
    Sep 2004
    Location
    United States
    Posts
    11,814
    Google has some good results:

    http://labmice.techtarget.com/articles/batchcmds.htm

    http://www.cknow.com/tutorcom/batch03_subcmd1.htm

    I just typed in PAUSE IN BATCH FILE in Google.

    hope some of that helps.

  3. #3
    Hammerhead Shark
    Join Date
    Mar 2001
    Location
    Littleton, CO
    Posts
    2,704
    There ought to be a sleep command of some sort, but then again, windows scripting isn't my thing.

    This machine has sleep on it, but I think it's a cygwin thing. If you don't want to install anything additional and this is really just a temporary quick-fix type of situation, you can always loop the batch file and do something pointless to keep it busy for a few seconds.

    This is all kinds of hackish and pretty stupid, but it slows this machine down for about 5 seconds:

    Code:
    @ECHO OFF
    for %%i in (1,2,3,4,5,6,7,8,9,0,a,b,c,d,e,f) 
      do for %%j in (1,2,3,4,5,6,7,8,9,0,a,b,c,d,e,f)
      do echo . > blah
    Have fun and good luck.

    Oh, and another avenue is to use windows scripting host. I'm positive it's powerful enough to stop and start services and has to have some sort of sleep function.

    EDIT: The indented pieces should be on the same line, but it caused vB to wrap nasty-like.
    Last edited by Nick_B; 03-01-2005 at 11:44 PM.
    Nick_B
    Currently running Ubuntu and Windows 7.

  4. #4
    Bearded Kirklander's Avatar
    Join Date
    Sep 2004
    Location
    United States
    Posts
    11,814
    You could write a little EXE in Delphi or something that does a simple pause for x number of seconds (passed by command line argument) I guess. I used to do that in Quick Basic 4.5 back in the day.

  5. #5
    BozoKiller
    Join Date
    Oct 2003
    Location
    Zoso
    Posts
    7,636
    use a double ampersands && in between the commands
    so;

    Net stop "dns client" && Net start "dns client"

    more examples;
    FORMAT A: /Q && COPY C:\DATA\*.* A:
    will copy all files from C:\DATA to diskette IF and ONLY IF the format succeeds.

    XCOPY C:\*.* D:\ /S 2>&1> NUL ¦¦ ECHO Something terrible happened
    will display your own custom error message if XCOPY fails

    the double pipes || is used to Execute command2 only if execution of command1 has finished unsuccessfully

    Source

    or even perhaps the Start /wait switch (which can be used with TIME)
    Delete the Electoral College - Support
    www.NationalPopularVote.com

    "The world according to DRM Bozos"

    I am a consumer, I'll buy anything
    I am a sheep, I am cattle, I follow the herd
    I am ignorant, a dumbass, and I am a bozo...
    I am the epitome of the 'rank and file'
    I am your next door neighbor
    I am 95% of American Consumers
    I will consume you

    • If the light in your head hasn't come on yet,
      I suggest you go get a new bulb!

  6. #6
    Reef Shark Stasis's Avatar
    Join Date
    May 2001
    Location
    Wenatchee, WA, USA
    Posts
    373
    thanks for the help all, im going with I4ones solution on this one, its quick and easy and thats what i need works great, thanks.

  7. #7
    Bearded Kirklander's Avatar
    Join Date
    Sep 2004
    Location
    United States
    Posts
    11,814
    Good post, I.

    I like learning new stuff. Did not know about that trick. Glad I do know. Thanks.

  8. #8
    BozoKiller
    Join Date
    Oct 2003
    Location
    Zoso
    Posts
    7,636
    your welcome both - I finally was able to find an easy effecive solution - but thank rob vanderwoude, (see source). I like to fiddle with batfiles from time to time and really don't know that much (that's the extent of my programming knowledge ) - and you'll be giving me some solutions on occasion when necessary.
    Delete the Electoral College - Support
    www.NationalPopularVote.com

    "The world according to DRM Bozos"

    I am a consumer, I'll buy anything
    I am a sheep, I am cattle, I follow the herd
    I am ignorant, a dumbass, and I am a bozo...
    I am the epitome of the 'rank and file'
    I am your next door neighbor
    I am 95% of American Consumers
    I will consume you

    • If the light in your head hasn't come on yet,
      I suggest you go get a new bulb!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •