| LOGGING a Whole Scripts Execution to stdout only [progress not seen by user].cmd.txt |
No progress is seen by the user unless outout is directed to the "CON" (console) device or the "TITLE" command is used.
echo This would go to the file echo This would go to the console for the user to see > CON TITLE This would update the titlebar of the Command Window
| The Code for: "LOGGING a Whole Scripts Execution to stdout only [progress not seen by user].cmd.txt" |
This is the example, a shortcut was installed to this code :
@echo off setlocal ::@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ :: $Header: C:/DBAREIS/Projects.PVCS/Win32/ScriptingTipsAndTricks/EXAMPLE[cmd].LOGGING a Whole Scripts Execution to stdout only [progress not seen by user].cmd.txt.pvcs 1.0 29 Jun 2014 12:51:20 USER "D$ ::@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ :: =============================================================================================== :: Note that since the execution of the whole script is logged (and we are not using "TEE.EXE" :: you won't see any console output (while logging) unless you redirect to stdout/stderr to the :: "CON" (console) device (that is demonstrated below in ":SAYSECTION". :: If "tee" used no "CON" logging is required. :: =============================================================================================== ::--- START: Turns logging on ----------------------------------------------- if "%~1" == "NOWLOGGING" goto NowLogging ::--- Remember original parameters -------------------------------------- set Parm1=%~1 ::--- Work out where we are logging to ---------------------------------- cls set LogDir=c:\Logs\[CaptureClusterIssueDetails.cmd] md "%LogDir%" >nul 2>&1 for /F "tokens=1,2,3,4 delims=/ " %%i in ('date /T') do set YYYYMMDD=%%l-%%k-%%j&set Day3=%%i set HHMMSSSS=%time::=_% set LogFile=%LogDir%\%YYYYMMDD% (%DAY3%) @ %HHMMSSSS% - %COMPUTERNAME%.txt echo LOGGING TO: "%LogFile%" ::--- Start logging ----------------------------------------------------- %0 "NOWLOGGING" > "%LogFile%" 2>&1 ::cmd.exe /c ""%~0" "NOWLOGGING" 2>&1 | tee.exe "%LogFile%"" ::--- Finished noth passes ---------------------------------------------- goto :EOF :NowLogging echo Now logging... > "CON" :: =============================================================================================== :: http://technet.microsoft.com/en-us/library/cc780572(v=ws.10).aspx#w2k3tr_scl_tools_xliq :: =============================================================================================== ::--- Look at Cluster ------------------------------------------------------- call :EXEC cluster.exe resource call :EXEC NET.exe SHARE ::--- http://support.microsoft.com/kb/961657 (and all services) ------------- call :EXEC SC.EXE query srv call :EXEC SC.EXE query ::--- Look at Network ------------------------------------------------------- call :EXEC ping.exe APPAU182FRM209 call :EXEC ping.exe max.anz call :EXEC dir M:\ call :EXEC dir N:\ ::--- Look at CPU/Processes ------------------------------------------------- set CpuMonitorPeriod=2000 call :SAYSECTION PV.EXE Process Info (monitor CPU for %CpuMonitorPeriod%ms) LOG.EXE $NoEOL "PgmName$x09Memory (K)$x09PID$x09PPID$x09Thread Count$x09Start Time$x09" LOG.EXE "Elapsed CPU Time$x09Percent CPU$x09User Name$x09Command Line" PV.EXE -o"%%n\t%%mK\t%%i\t%%r\t%%t\t%%d\t%%e\t%%c%CpuMonitorPeriod%%%%%\t%%u\t%%l" call :EXEC Process.exe call :EXEC PsList.exe /accepteula call :EXEC PsList.exe /accepteula -m call :SAYSECTION All Done... goto :EOF ::=========================================================================== :EXEC ::=========================================================================== set CMD=%* call :SAYSECTION EXEC: %CMD% %CMD% goto :EOF ::=========================================================================== :SAYSECTION ::=========================================================================== TITLE echo %* echo.&echo.&echo. echo =========================================================================================================== echo [%date% %Time%] %* echo [%date% %Time%] %* >CON echo =========================================================================================================== goto :EOF
Please note that that I am not trying to show how great I am by producing batch files 9,000 characters long on one line that no one will understand or be able to debug when they go wrong. I am going out of my way to comment the code and make it verbose so beginners and advanced users will both benefit. I don't claim to be an expert that knows everything, if I'm wrong or make a mistake then please contact me and let me know :-)
![]() | ![]() |