1

I have 6 batch files each making a curl request. I want to run those files asynchronously. Now, I want to calculate the time taken by all the scripts. i.e. time elapsed between starting the scripts until the time last one finishes. I have used 'START' command to run the batch scripts from a parent script. Here is how the parent scripts looks like :

ECHO Start Measure %Time% >> timer.txt
start curl-1.bat
start curl-2.bat
start curl-3.bat
start curl-4.bat
start curl-5.bat
start curl-6.bat
ECHO Stop measure %Time% >> timer.txt

But the times that are registered are just the times at the point of those %Time% statements are executed. I believe this is because, 'START' command starts separate shells and the called scripts don't return back.

Using 'CALL' command will not let me make asynchronous calls. Hence, that option rules out. Can anyone suggest a way to achieve this?

User3518958
  • 676
  • 1
  • 6
  • 19

1 Answers1

1

To do what you want, you would need to seperate commands by single pipe:

echo Start Measure %Time%>>timer.txt
curl-1.bat | curl-2.bat | curl-3.bat | curl-4.bat | curl-5.bat | curl-6.bat
echo Stop measure %Time%>>timer.txt

I would however say to rather redirect output to nul as only one of the commands will display to screen during the process, which might seem confusing:

echo Start Measure %Time%>>timer.txt
curl-1.bat>nul | curl-2.bat>nul | curl-3.bat>nul | curl-4.bat>nul | curl-5.bat>nul | curl-6.bat>nul
echo Stop measure %Time%>>timer.txt
Gerhard
  • 22,678
  • 7
  • 27
  • 43
  • Hi Gerhard, I tried above script with batch script calls redirected to null. From the response it is not clear whether it is echoing the time after the last script finished. And from the time, it does not look like. Also, tried w/o redirecting, the script is giving syntax errors. – User3518958 Feb 05 '19 at 09:32
  • You can simply test if the time makes sense. create 2 batch files. `bat1.cmd` and `bat2.cmd` do `ping localhost -n 3` in `bat1.cmd` and `ping localhost -n 11` on `bat2.cmd` then run them as above. We know bat1 wil take more or less 2 seconds. and bat2 will take 10 seconds, so the total time both scripts took from start to finish should be 10 seconds, if that is the case, then it means it does work, right? :) As for syntax error, make sure you do not have missing space between characters and pipe. it is a simple typo. – Gerhard Feb 05 '19 at 09:37
  • Oh okay, thanks! Let me try this. :) – User3518958 Feb 05 '19 at 09:46