Other Languages - .bat files - Asked By Henry Taylor on 16-May-12 03:49 PM

I am trying to execute the same program multiple times from a .bat file.  There is logging going on so the program cannot run two instances at once because we get errors trying to open and write to the log file if it is already in use.

The /wait and /b options are used to control that but it is not working. /b tells the next process to use the same window.

Here is a sample file:

@echo off
start "Batch Process" /wait "BatchProcessScriptor.exe" 290,2/23/2012
start "Batch Process" /wait /b "BatchProcessScriptor.exe" 310,2/23/2012
start "Batch Process" /wait /b "BatchProcessScriptor.exe" 320,2/23/2012
start "Batch Process" /wait /b "BatchProcessScriptor.exe" 330,2/23/2012
start "Batch Process" /wait /b "BatchProcessScriptor.exe" 340,2/23/2012

The processes that are supposed to run here are 290, 310, 320, 330 and 340 in that order. 290 always starts first but then things go bad and it might jump to 330.  It doesn't seem to be "waiting" before executing the next line.  It seems like it is trying to run all of them at once.
S K replied to Henry Taylor on 16-May-12 11:34 PM
You can use sleep to wait for your desired time interval so you put these command where you want to wait

eg
SLEEP 3600


hope this helps you
Henry Taylor replied to S K on 04-Jun-12 09:29 AM
The way to do this is to forget about .bat files and go with PowerShell:

#If your scripts don't run execute the command below:
#Set-ExecutionPolicy RemoteSigned

cd "c:\Program Files\XCorp\Scheduler"

$runDate = Get-Date "5/18/2012"
$batchList = (290,310,320,340,380)
$BPScriptor = "BatchProcessScriptor.exe"

foreach ($batch in $batchList)
{     
    start-process $BPScriptor $batch, $runDate -wait
}