Windows Batch File-Wait Script

Something I work with all the time, is a “file wait” need to kick off ETL processes especially conditionally from an ETL tool.  I’ve always used a conditional file-wait method, and just wanted to share this with you.

Here is a Windows BATCH file Script that will wait conditionally for a file to “appear”, and will exit based on two different conditions:

[code]

@Set Runtry=0
:START
@if exist %3 (
  @exit(0)
)
@sleep %1
@Set /A Runtry+=1
@if %Runtry% lss %2 goto :START
:ErrorOut
@echo %runtry% exiting
exit(-1)

[/code]

 

the file should be called: CHECK.BAT

So: CHECK 30 5 MyFile.txt

will wait 30 seconds between “checking”, and will check for the file 5 times, then exit.

The Exit(0) is success, and the exit(-1) is the failure condition.

I hope you find this helpful.

Dan Linstedt

Tags: , , ,

2 Responses to “Windows Batch File-Wait Script”

  1. Satish Jampa 2011/09/06 at 11:10 am #

    Hi Dan,

    Thanks a lot for your post. im trying to do the same, I create a check.bat file and can use this code. how do i call this in RED via scheduler or host scripts.
    Can you throw some light on how it is done via host scripts. i mean calling the .bat file . pleae

  2. dlinstedt 2011/09/06 at 1:38 pm #

    Hi Satish,

    Not sure I understand your question. If you are referring to executing the BAT file from Wherescape RED, then I’m afraid I don’t have the answer. I’m not yet trained on RED – that should happen soon though. In the mean time a quick question to the Wherescape team from you, should do the trick, They should give you the answer right away.

    Hope this helps,
    Dan L

Leave a Reply

*