I'm trying to create an alarm clock service via CMD Prompt. The service can be programmed to a certain time, and will play a song and ask a question before terminating. I'm running into two difficulties:
1) The command prompt window opens and then closes when it reaches the if/else
statement (doesn't even pause after the if/else
as coded below). Is my if
statement faulty? It was literally working up until the time changed to 11:00 PM, and then the faulty behavior began.
2) Using more
in the for loop to read the nth line of a file (https://stackoverflow.com/a/6410343/3746582) gave an error saying Cannot access file (filename)
before the if/else statement started to fault. Any thoughts?
@ECHO OFF
rem Alarm generated that won't turn off until interacted by user.
rem Get time
For /f "tokens=1-2 delims=/:" %%a in ("%TIME%") do (set mytime=%%a%%b)
if %mytime% == 2328 (
start wmplayer "C:\Users\Public\Music\Sample Music\Kalimba.mp3"
pause
rem Stop music with user input
taskkill /im "wmplayer.exe"
rem Pick random question
SET /a _rand=%RANDOM%*216929/32768+1
SET /a _rand-=1
For /f "tokens=6-7 delims=," %%a in (more +%_rand% 'JEOPARDY_CSV.txt') do (set /a myquestion = %%a && set /a myanswer = %%b)
set /p userinp=Answer the question of the day! %myquestion%:%=%
pause
) else (
pause
)
pause
Thanks!