• 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