So in my batch file, I can capture the errorlevel (the error number), but the system is also outputting it's own error msg to the user, how do I capture that msg?
OS: Windows 2003 Server
Here is what I get when I run the batch file (I know what's causing it, I just want to log the msg I get back when it's run)
D:\>cm_build.bat
System error 1219 has occurred.
Multiple connections to a server or shared resource by the same user, using more
than one user name, are not allowed. Disconnect all previous connections to the
server or shared resource and try again..
Here is what I get in the Logfile:
------------------------------------------------
-- Batch Ran on Tue 05/11/2010 at 8:57:05.97 --
------------------------------------------------
Error: Tue 05/11/2010 at 8:57:06.12
Error Location: UnMapped
Error Msg: error during mapping, Error Number: 2
Here's a snippet of the code:
@echo off
set logLocation="d:\BuildLogs.txt"
set deletedFoldersList="deletedfolders.txt"
echo ------------------------------------------------ >> %logLocation%
echo -- Batch Ran on %date% at %time% -- >> %logLocation%
echo ------------------------------------------------ >> %logLocation%
for /f "tokens=2-3" %%i in ('net use ^| find /i "Z:"') do (
IF %ERRORLEVEL% EQU 0 (
set local=%%i
set remote=%%j
goto :successfulRun
) ELSE (
goto :UnMapped
)
)
:UnMapped
echo unmapped >> %logLocation%
net use Z: \\a_drive\a_directory /USER:username password
IF %ERRORLEVEL% NEQ 0 (
set errorLoc=UnMapped
set errorMsg=error during mapping, Error Number: %ERRORLEVEL%
goto :errorFound
)
goto :successfulRun
:successfulRun
echo -- Batch run completed successfully on %date% at %time% -- >> %logLocation%
goto :eof
:errorFound
echo Error: %date% at %time% >> %logLocation%
echo Error Location: %errorLoc% >> %logLocation%
echo Error Msg: %errorMsg% >> %logLocation%
goto :eof
So I'm curious if there's a way to put that system msg from the dos prompt:
System error 1219 has occurred.
Multiple connections to a server or shared resource by the same user, using more
than one user name, are not allowed. Disconnect all previous connections to the
server or shared resource and try again..
into the log files? Being able to do caputer the dos system messages will go a long way in helping me to debug this batch file when it's run from scheduled tasks while the user is logged off.
Thx!