Skip to content

Instantly share code, notes, and snippets.

@ostapel
Last active August 29, 2015 14:06
Show Gist options
  • Save ostapel/5d87dcd9772f405ef1d5 to your computer and use it in GitHub Desktop.
Save ostapel/5d87dcd9772f405ef1d5 to your computer and use it in GitHub Desktop.
Parallel run via batch file
echo "Arg 1 is"%1%
echo "Arg 2 is"%2%
IF "%1"=="" (
echo "Argument: browser was not set"
exit -1
)
IF "%2"=="" (
echo "Argument: N of executors was not set. 2 or 4 are supported"
set FORKS="4"
) else (
set FORKS="%2"
)
del "*lock*"
set "lock=.\wait%random%.lock"
if %FORKS%=="4" (
:: Launch asynchronously, with stream 9 redirected to a lock file.
:: The lock file will remain locked until the script ends.
start "" cmd /c 9>"%lock%1" mvn integration-test -Dsuite="Suite1" -Dbrowser=%1%
start "" cmd /c 9>"%lock%2" mvn integration-test -Dsuite="Suite2" -Dbrowser=%1%
start "" cmd /c 9>"%lock%3" mvn integration-test -Dsuite="Suite3" -Dbrowser=%1%
start "" cmd /c 9>"%lock%4" mvn integration-test -Dsuite="Suite4" -Dbrowser=%1%
:Wait4 for both scripts to finish (wait until lock files are no longer locked)
1>nul 2>nul ping /n 2 ::1
for %%N in (1 2 3 4) do (
( rem
) 9>"%lock%%%N" || goto :Wait4
) 2>nul
echo %ERRORLEVEL%
::delete the lock files
del "%lock%*"
)
if %FORKS%=="2" (
:: Launch one and two asynchronously, with stream 9 redirected to a lock file.
:: The lock file will remain locked until the script ends.
start "" cmd /c 9>"%lock%1" mvn integration-test -Dsuite="SuiteFirst" -Dbrowser=%1%
start "" cmd /c 9>"%lock%2" mvn integration-test -Dsuite="SuiteSecond" -Dbrowser=%1%
:Wait2 for both scripts to finish (wait until lock files are no longer locked)
1>nul 2>nul ping /n 2 ::1
for %%N in (1 2) do (
( rem
) 9>"%lock%%%N" || goto :Wait2
) 2>nul
echo %ERRORLEVEL%
::delete the lock files
del "*lock*"
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment