Capture t-sql error occured in xp_cmdshell

  • Is there a way to capture the t sql error occured while running the tsql script via xp_cmdshell ???

    Help is really appreciated!!

  • You can capture the output from a command executed with xp_CMDshell by doing something like this:

    DECLARE @CMD VarChar(500)

    DECLARE @Results TABLE

    (

    ID Int Not Null IDENTITY(1,1),

    Line VarChar(256)

    )

    SET @CMD = 'dir C:\'

    INSERT INTO @Results (Line)

    EXEC xp_CMDShell @CMD

    SELECT *

    FROM @Results

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply