[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 385
  • Last Modified:

Call a Batch File and Wait Til Complete

Hello Experts!

I need to write a program that will loop through a series of date directories and pass in the folder name to a batch file, let the batch file run and then loop to the next directory.

For Example:
        For Each ProcessDate In clb_ProcessDates.CheckedItems
            Call Shell("Run.bat" & " " & ProcessDate.ToString)
        Next

The probblem is I need to wait til the Run.bat (Batch File) has completed until I move on to the next process date.

How can I determine when the batch file has completed and move to the next date?

Thanks,
Mark
0
smithmrk
Asked:
smithmrk
  • 2
  • 2
1 Solution
 
wdosanjosCommented:
Please try the following:

        For Each ProcessDate In clb_ProcessDates.CheckedItems
            Dim p As Process = Process.Start("Run.bat" & " " & ProcessDate.ToString)
            p.WaitForExit()
        Next

Open in new window


More on the Process class here:
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx

0
 
smithmrkAuthor Commented:
I tried that already, and I get file not found.  The problem is my paramater (ProcessDate.String), the Process.Start doesn't like it, because if I take out the paramater and just run (Run.bat) it works fine.

I need the ablity to pass in that paramater into the batch file.

Mark
0
 
wdosanjosCommented:
Please give the following a try. It worked for me here, that is Process.Start(cmd, args).

        For Each ProcessDate In clb_ProcessDates.CheckedItems
            Dim p As Process = Process.Start("Run.bat", ProcessDate.ToString)
            p.WaitForExit()
        Next

Open in new window

0
 
smithmrkAuthor Commented:
Perfect!!!!!

Thanks,
Mark
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now