Calling Python through batch file and getting date and time

call:SendEmail %Recipient% %EMAIL_SUB% %EMAIL_MESSAGE%

:SendEMail
call:GetDateTime
@echo %DD%-%MM%-%YY% %hr%:%min%:%sec% “INFO: Sending status mail started to %Recipient%”>>%LOGFILE%
echo %Recipient%
echo %EMAIL_SUB%
echo %EMAIL_MESSAGE%
python -c ^
“import ciFunctions ; ^
ciFunctions.sendEmail(“%EMAIL_SUB%”,”%EMAIL_MESSAGE%”)”
call:GetDateTime
@echo %DD%-%MM%-%YY% %hr%:%min%:%sec% “INFO: Mail sent successfully to %Recipient%”>>%LOGFILE%

rem # Sub process to get date and time for logging
:GetDateTime
for /f “delims=” %%a in (‘wmic OS Get localdatetime ^| find “.”‘) do set dt=%%a
set datestamp=%dt:~0,8%
set timestamp=%dt:~8,6%
set DD=%datestamp:~6,2%
set MM=%datestamp:~4,2%
set YY=%datestamp:~0,4%
set hr=%timestamp:~0,2%
set min=%timestamp:~2,2%
set sec=%timestamp:~4,2%

goto:EOF

Leave a comment