All,
I am using a batch file to automate the deployment of SSIS packages out to MSDB. I am using a START /WAIT command in a FOR loop to iterate through all files in a folder and execute the DTUTIL command.
While I know I can return the %ERRORLEVEL% and use it in the main batch process, what I am losing is the specific error message that DTUTIL outputs.
I want to be able to capture that message output, but I have yet to find a way to. I tried chaining commands by using the &&, || and & concatenation commands. And I also tried to use > and 2> to put the output into a file. Nothing has given me the desires output.
And to be specific, I’m mainly concerned with when DTUTIL ERRORS and the message is more relevant than the error code alone.
Any help or recommendations would be appreciated. Here’s the code:
@echo off
SET /P SOURCEFOLDER=Enter the Source Folder where the Packages are located:
SET /P DESTSERVER=Enter the Destination Server:
SET /P DESTLOCATION=Enter Destination Folder (Leave blank for root):
IF NOT EXIST "%SOURCEFOLDER%\*.dtsx" GOTO NOFILES
FOR /F "usebackq delims==" %%i in (`dir /b "%SOURCEFOLDER%\*.dtsx"`) do (
ECHO.
ECHO ^>^>^>^>^>^> Copying %%i to %DESTSERVER%\MSDB\%DESTLOCATION% ^<^<^<^<^<^<^<
ECHO.
START /WAIT dtutil /FILE "%SOURCEFOLDER%\%%i" /DESTSERVER %DESTSERVER% /COPY SQL;"%DESTLOCATION%\%%~ni" /QUIET
ECHO %ERRORLEVEL%
ECHO.
)
GOTO COMPLETE
:NOFILES
ECHO.
ECHO *** No SSIS Packages were found. Please verify the folder location:
ECHO %SOURCEFOLDER%
ECHO.
GOTO END
:COMPLETE
ECHO.
ECHO All Packages have been Processed.
ECHO Please verify that no Error Messages or Warnings were returned.
ECHO.
GOTO END
:END
PAUSE
Simplest would be to drop start and just issue Dtutil (since you wait till it finishes I cannot see a difference). Another two possibilites
or
(^ is used to escape special chars, here redirection symbol >) (and you already use it…)
Redirect stderr would be
2>result.txt, both stdout and strerr>result.txt 2>&1(escaped if used with cmd /c:^>result.txt 2^>^&1)