Wait for bat file to complete before continuing

  • Hi,

    Please help with the following.

    I have an Execute Process Task calling a bat file, (File1) with arguments, in a loop. I want SSIS to wait for it to complete before going to the next value in the loop. It doesn't seem to do that.

    The File1 that SSIS calls makes a call to rcmd to run File2. I added start /WAIT to File1 but that didn't help. With this, SSIS runs the File2 sucessfully for first iteration of the loop and then hangs. Also, a DOS window gets opened to show what it is executing from File2, even though I have @ECHO OFF in File2. Until I close the DOS window the loop doesn't continue.

    File1:

    @ECHO OFF

    start /WAIT rcmd \\abcdetl01 E:\FOlDER\SFDC\EXTRACT.bat %1 %2 %3 %4 %5

    File2:

    CAlls an exe to run and do stuff.

    Thanks,

    Juls

  • I've added sql task that executes WAITFOR DELAY '0:02' --2 minute wait

    between steps. its not the best, but has worked. i just never searched for a real solution, which would be to receive a response that one task has completed

  • I'm not doing anything special and my ProccessTasks wait for the batch file to finish.



    Alvin Ramard
    Memphis PASS Chapter[/url]

    All my SSC forum answers come with a money back guarantee. If you didn't like the answer then I'll gladly refund what you paid for it.

    For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]

  • i've also encountered this problem. my solution was to check to see if there was an open connection to the program that the BAT file was calling.

    for example, my BAT file called a process "abcd.exe". if this process was already open, my T-sql would not wait until the processed actually finished, thus making my entire script fail.

    now, i check to see if abcd.exe is open before calling my BAT file. if its not open, a new connection is created and sql will wait until the process finishes before continuing.

  • Use this Code to run the bat job where xxxxxxxxx.bat is you bat file:

    Dim procID As Integer

    Dim newProc As Diagnostics.Process

    newProc = Diagnostics.Process.Start("C:\ftp\xxxxxxxxx.bat")

    procID = newProc.Id

    newProc.WaitForExit()

    Dim procEC As Integer = -1

    If newProc.HasExited Then

    procEC = newProc.ExitCode

    End If

    MsgBox("Process with ID " & CStr(procID) & _

    " terminated with exit code " & CStr(procEC))

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply