Output the results of two commands in parallel

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Blitz
Posts: 2
Joined: 09 Oct 2021 15:23

Output the results of two commands in parallel

#1 Post by Blitz » 09 Oct 2021 16:15

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

Aacini
Expert
Posts: 1885
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Output the results of two commands in parallel

#2 Post by Aacini » 09 Oct 2021 21:23

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...

Blitz
Posts: 2
Joined: 09 Oct 2021 15:23

Re: Output the results of two commands in parallel

#3 Post by Blitz » 10 Oct 2021 02:59

Yes, I know, I mean their output can be side by side and there is no need for temporary files or setting variables

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Output the results of two commands in parallel

#4 Post by aGerman » 10 Oct 2021 04:34

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

Hackoo
Posts: 103
Joined: 15 Apr 2014 17:59

Re: Output the results of two commands in parallel

#5 Post by Hackoo » 10 Oct 2021 08:41

Hi :wink:
Perhaps you mean that you want to make something like this code : Multi-Threaded_Network_IP_Ports_Scanner.bat

Post Reply