Partially, you can achieve this following way:
DECLARE @output TABLE (lines varchar(2000))
DECLARE @ReturnCode INT
INSERT INTO @output
EXEC @ReturnCode=xp_cmdshell @cmd
IF @ReturnCode <>0
BEGIN
--do something with output
SELECT lines FROM @output WHERE lines IS NOT NULL
END
However, as @under mentioned, consider to use SSIS Catalog. in that case accomplishment of your task could be much simpler:
Start of SSIS package:
Declare @execution_id bigint
EXEC [SSISDB].[catalog].[create_execution] @package_name=N'Package.dtsx',
@execution_id=@execution_id OUTPUT,
@folder_name=N'Deployed Projects',
@project_name=N'Integration Services Project1',
@use32bitruntime=False,
@reference_id=Null
Select @execution_id
EXEC [SSISDB].[catalog].[start_execution] @execution_id
Querying for errors:
SELECT * FROM SSISDB.catalog.event_messages
WHERE operation_id = @execution_id AND event_name = 'OnError'