I wanted to know if I could run multiple functions (processes) on my single batch file. I found a simple technique to do this and it works for running multiple infinite loops at the same time, which is nice.
I played around and found making it run a little more complex it ran into some issues and didn't work after all.
Code: Select all
@echo off
if not "%1" == "" goto :%1
start /b %~nx0 2
start /b %~nx0 3
:1
echo Thread 1 Loop
ping localhost -n 2 >nul
goto :1
:2
echo Thread 2 Loop
ping localhost -n 2 >nul
goto :2
:3
echo Thread 3 Loop
ping localhost -n 2 >nul
goto :3
[\code]
The simple multi-theading code is above and does work as I explained earlier.
But I wanted something more 'stable', (1) for example the file name doesn't work with spaces:
"C:\Users\Adrian\Desktop\multi theading\multi.bat" - doesn't work.
"C:\Users\Adrian\Desktop\multitheading\multi.bat" - works.
(2) How do I get it to support multiple arguments?
[code]
if not "%1" == "" echo(
start /b %~nx0 checkcalcDurationReg /d /r
echo Running simulation
pause
:checkcalcDurationReg
echo Running new process
set "/d="&set "/r="
for %%a in (%*) do (
if "%%~a"=="/d" ( set "/d=true"
) else if "%%~a"=="/r" set "/r=true"
)
if defined /d set calcLoadingDurationmode=Enabled
if defined /r (
reg query "%RegKey%" /v "CALC_LOADING_DURATION" >nul 2>nul
if "!errorlevel!"=="0" for /f "tokens=2*" %%i in ('reg query "%RegKey%" /v "CALC_LOADING_DURATION"') do set "calcLoadingDurationmode=%%j"
if "%calcLoadingDurationmode%"=="Enabled" (exit /b
) else if "%calcLoadingDurationmode%"=="Disabled" (exit /b
) else ( >nul reg delete "%RegKey%" /v "CALC_LOADING_DURATION" /f )
call :checkcalcDurationReg /d
>nul reg add "%RegKey%" /v "CALC_LOADING_DURATION" /t REG_SZ /d "%calcLoadingDurationmode%" /f )
echo end of process
exit /b
I need a way (if possible) to run mulitple threads within one batch file with supportive file name directories and to call parameters for a function, within the same batch file.
If anyone could help me out here that would be great!
Kind regards,
Adrian