Page 1 of 1

Output the results of two commands in parallel

Posted: 09 Oct 2021 16:15
by Blitz
I hope this trick can help anyone

1.bat

Code: Select all

@echo off
for /l %%a in  (1,1,10) do echo=%%a
2.bat

Code: Select all

@echo off
for /l %%a in (1,1,15) do echo=%%a
Parallel.bat

Code: Select all

@echo off
(for /f "delims=" %%a in ('1') do @echo=%%a&ping 127.1 -n 1 >nul)|cmd /v /c "(for /f "delims=" %%b in ('2') do @(set/pa=&&echo=!a!		%%b||echo=		%%b))&&for /l %%c in (,,,) do @set /pa=&&echo=!a!||exit /b"
pause

Re: Output the results of two commands in parallel

Posted: 09 Oct 2021 21:23
by Aacini
If you say that 1.bat and 2.bat are executed in parallel, then you are wrong. The FOR/F command first run the command and then, after the command had finishef, output the results. 1.bat and 2.bat never run in parallel in this way...

Re: Output the results of two commands in parallel

Posted: 10 Oct 2021 02:59
by Blitz
Yes, I know, I mean their output can be side by side and there is no need for temporary files or setting variables

Re: Output the results of two commands in parallel

Posted: 10 Oct 2021 04:34
by aGerman
I'm not even sure if this works reliably. Looks rather like some kind of UB. What happens if you decelerate one of the output loops? E.g. in 2.bat

Code: Select all

@echo off
for /l %%a in (1,1,15) do ping 127.1 -n 2 >nul&echo=%%a
Steffen

Re: Output the results of two commands in parallel

Posted: 10 Oct 2021 08:41
by Hackoo
Hi :wink:
Perhaps you mean that you want to make something like this code : Multi-Threaded_Network_IP_Ports_Scanner.bat