capturing xp_cmdshell output

  • Hi,

    I am calling an executable by using

    EXECUTE master..xp_cmdshell 'xyz.exe'

    I know that I can capture the int result by:

    DECLARE @iResult int
    EXECUTE @iResult = master..xp_cmdshell 'xyz.exe'

    That works fine.

    My executable also writes out text to the console.

    Execute appears to convert the text into rows in a temp table in a column called output. For example if my exe writes "Hi Rick" to the console, I get a result with one row with a column called Output with the contents "Hi Rick"

    Can I access that temp table?

    I have seen code that redirects standard out to a text file, and then BULK INSERTS into a temp table tha

    CREATE TABLE #xyzout (coutput varchar(1000))
    EXECUTE master..xp_cmdshell 'xyz.exe > d:\xyzout.txt'
    BULK INSERT .... INTO #xyzout
    DECLARE @lcResults varchar(1000)
    SELECT @lcResults + "\n" + cOutput FROM #xyzout

    Is there a simpler way that omits the redirection and bulk insert?


    Thanks,

    Rick Hodder

  • CREATE TABLE #xyzout ...

    Insert into #xyzout (FieldName) EXECUTE master..xp_cmdshell 'xyz.exe

    Select * from #xyzout

  • Perfect!


    Thanks,

    Rick Hodder

  • HTH.

Viewing 4 posts - 1 through 3 (of 3 total)

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