jpe ソリューションでは、出力ファイルのサイズを確認する前に、開始されたプロセスがいつ完了したかを親バッチが知る必要があります。START /WAIT オプションを使用できますが、並列実行の利点が失われます。
別のプロセスがすでに同じファイルに出力をリダイレクトしている場合、ファイルへのリダイレクトは失敗するという事実を利用できます。親バッチがそれらに正常にリダイレクトされると、開始されたプロセスがすべて完了したことがわかります。
おそらく、stderr を stdout だけでなく出力ファイルにもリダイレクトする必要があります。
@echo off
::start the processes and redirect the output to the ouptut files
start /b "" cmd /c prog.exe cmdparam1 cmdparam2 >test1.txt 2>&1
start /b "" cmd /c prog.exe cmdparam1 cmdparam2 >test2.txt 2>&1
::define the output files (must match the redirections above)
set files="test1.txt" "test2.txt"
:waitUntilFinished
:: Verify that this parent script can redirect an unused file handle to the
:: output file (append mode). Loop back if the test fails for any output file.
:: Use ping to introduce a delay so that the CPU is not inundated.
>nul 2>nul ping -n 2 ::1
for %%F in (%files%) do (
9>>%%F (
rem
)
) 2>nul || goto :waitUntilFinished
::Delete 0 length output files
for %%F in (%files%) do if %%~zF==0 del %%F