Question

I have the following layout for my test suite:

TestSuite1.cmd:

  1. Run my program
  2. Check its return result
  3. If the return result is not 0, convert the error to textual output and abort the script. If it succeeds, write out success.

In my single .cmd file, I call my program about 10 times with different input.

The problem is that the program that I run 10 times takes several hours to run each time.

Is there a way for me to parallelize all of these 10 runnings of my program while still somehow checking the return result and providing a proper output file and while still using a single .cmd file and to a single output file?

Was it helpful?

Solution

Assuming they won't interfere with each other by writing to the same files,etc:

test1.cmd

:: intercept sub-calls.
  if "%1"=="test2" then goto :test2

:: start sub-calls.
  start test1.cmd test2 1
  start test1.cmd test2 2
  start test1.cmd test2 3

:: wait for sub-calls to complete.
:loop1
  if not exist test2_1.flg goto :loop1
:loop2
  if not exist test2_2.flg goto :loop2
:loop3
  if not exist test2_3.flg goto :loop3

:: output results sequentially
  type test2_1.out >test1.out
    del /s test2_1.out
    del /s test2_1.flg
  type test2_2.out >test1.out
    del /s test2_2.out
    del /s test2_2.flg
  type test2_3.out >test1.out
    del /s test2_3.out
    del /s test2_3.flg

  goto :eof
:test2

:: Generate one output file
  echo %1 >test2_%1.out
  ping -n 31 127.0.0.1 >nul: 2>nul:

:: generate flag file to indicate finished
  echo x >test2_%1.flg

This will start three concurrent processes each which echoes it's sequence number then wait 30 seconds.

All with one cmd file and (eventually) one output file.

OTHER TIPS

Running things in parallel in batch files can be done via 'start' executable/command.

Windows:

you create a Batch File that essentially calls:

start TestSuite1.cmd [TestParams1]
start TestSuite1.cmd [TestParams2]

and so on, which is essentially forking new command lines,

which would work, if the application can handle concurrent users (even if its the same User), and your TestSuite1.cmd is able to handle parameters.

You will need to start the script with different parameters on different machines because whatever makes the program take so long for a task (IO, CPU time) will be in even shorter supply when multiple instances of your program run at once.

Only exception: the run time is cause by the program putting itself to sleep.

try the command start, it spawns a new command prompt and you can send along any commands you want it to run.

I'd use this to spawn batch files that run the tests and then appends to a output.txt using >> as such:

testthingie.cmd >> output.txt
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top