Forum Discussion
wnjj
Sep 06, 2019Explorer II
First, as others have pointed out your log file name is built using the date and therefore will not be reused.
Second, why not simplify it all by just always writing the date, then the command, then the separator? That way no branching is required.
set LogPath=C:\RestartServices\
set LogFileExt=.log
set LogFileName=RestartInternalDatabaseServices
set MyLogFile=%LogPath%%LogFileName%%LogFileExt%
echo %Date% >> "%MyLogFile%"
echo %Time% >> "%MyLogFile%"
net start MSSQL$MICROSOFT##WID >> "%MyLogFile%"
echo “===================“ >>"%MyLogFile%"
Note that I didn’t test this so may have spaces or quotes wrong.
Second, why not simplify it all by just always writing the date, then the command, then the separator? That way no branching is required.
set LogPath=C:\RestartServices\
set LogFileExt=.log
set LogFileName=RestartInternalDatabaseServices
set MyLogFile=%LogPath%%LogFileName%%LogFileExt%
echo %Date% >> "%MyLogFile%"
echo %Time% >> "%MyLogFile%"
net start MSSQL$MICROSOFT##WID >> "%MyLogFile%"
echo “===================“ >>"%MyLogFile%"
Note that I didn’t test this so may have spaces or quotes wrong.
About RV Must Haves
Have a product you cannot live without? Share it with the community!8,793 PostsLatest Activity: Feb 08, 2025