I am trying to calculate/instrument time taken for a command/script to execute. Here's the batch file:
@echo off
setlocal EnableDelayedExpansion
echo "Starting the script run...." & echo/
set "startTime=%time: =0%"
echo "Initial Start: %startTime%" & echo/
(CALL node test_node_script.js) && (
set "endTime=%time: =0%"
echo "Initial End: %endTime%"
rem Get elapsed time:
set "end=!endTime:%time:~8,1%=%%100)*100+1!" & set "start=!startTime:%time:~8,1%=%%100)*100+1!"
set /A "elap=((((10!end:%time:~2,1%=%%100)*60+1!%%100)-((((10!start:%time:~2,1%=%%100)*60+1!%%100), elap-=(elap>>31)*24*60*60*100"
set /A "totalTime=elap/100"
echo "Elaps time: %totalTime%" & echo/
rem Convert elapsed time to HH:MM:SS:CC format:
set /A "cc=elap%%100+100,elap/=100,ss=elap%%60+100,elap/=60,mm=elap%%60+100,hh=elap/60+100"
echo "Start: %startTime%" & echo/
echo "End: %endTime%" & echo/
echo "Elapsed: %hh:~1%%time:~2,1%%mm:~1%%time:~2,1%%ss:~1%%time:~8,1%%cc:~1%" & echo/
) || (
echo "script failed" & echo/
)
the example node script(test_node_script.js
):
async function init() {
console.log(1);
await sleep(1000);
console.log(2);
}
function sleep(ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}
init()
The issue is that the endTime
is not being set in the batch file for some reason. Here's the output that I see in the cmd:
"Starting the script run...."
"Initial Start: 16:45:28.56"
1
2
"Initial End: "
"Elaps time: 0"
"Start: 16:45:28.56"
"End: "
"Elapsed: 00:00:00.00"
How do I get the endTime
so this calculation works?