Can't be done? Dingo's kidneys!
If batch can be used to create the universe as we know it, there's not much that it can't do - if you're flexible.
For instance, here's a demo that will have a batch wait on the output of two processes - all it needs is a little co-operation.
@ECHO OFF
SETLOCAL
FOR %%i IN (1 2) DO DEL proc%%i.finished 2>nul&SET proc%%i=&START proc%%i
:loop
FOR %%i IN (1 2) DO IF EXIST proc%%i.finished CALL :getdata %%i
FOR %%i IN (1 2) DO IF NOT DEFINED proc%%i timeout /t 1 >NUL &GOTO loop
SET proc
GOTO :eof
:getdata
DEL proc%1.finished
FOR /f "delims=" %%o IN (proc%1.output) DO SET proc%1=%%o
DEL proc%1.output
GOTO :eof
This sends off two processes, proc1
and proc2
(I'm good at creating imaginative tasknames...) It then waits until a file procN.finished
is created and processes the corresponding procN.output
(just puts the output line into envvar PROCn
)
When both subsidiary procs are complete, it proceeds - well, to EOF in this case...
Here's an example of a subsidiary proc I used for testing:
@echo off
setlocal enabledelayedexpansion
set /a delay=2+(%random% %% 3)
timeout /t %delay%
>proc2.output ECHO Finished AT %DATE% %TIME%
ECHO.>proc2.finished
EXIT
proc1.bat
was the same, with a few numbers changed.
Works fine - with the SET displaying the end time of the two subsidiary processses as expected.
All it takes is to poke the appropriate output string into a file and use flag files to notify the controlling batch that the subsidiary processes have finished doing their work.
Of course, the original question is a litle hazy, and I may have it all completely confused...
cmdA | cmdB
- the output ofcmdA
will be input tocmdB
- or is that still not what you wanted?