cmdShell output

  • How can I capture part of the output of the following sp into variables, i.e. the packets send and received ?

    DECLARE @cmd sysname, @strHost varchar(30)

    SET @strHost = '127.0.0.1'

    SET @cmd = 'ping ' + @strHost

    EXEC master..xp_cmdshell @cmd

  • You can't capture the output into variables because the xp return a rowset but you can place the result of xp to a table.

  • I am running the following way for the scheduled jobs in SQL Server 6.5 so that they will create the outfiles, since there is no option in SQL 6.5 to generate outfiles for jobs. I guess we can implement the same for above question as well.

    In Schedular, I am scheduling d:\bat\FTPIN.bat as cmdexec job. The content of the files are as follows:

    Content of d:\bat\FTPIN.bat:::

    d:

    cd \mssql\binn

    isql.exe -U userid -S server -P password -id:\sql\FTPIN.sql -od:\outfiles\FTPIN.out

    (OR) you can pass then as parameters as follows for have more security:

    isql.exe -U %1 -S %2 -P %3 -id:\sql\FTPIN.sql -od:\outfiles\FTPIN.out

    Content of d:\sql\FTPIN.sql :

    Use DATABASE1

    go

    exec master..xp_cmdshell"ftp -s:d:\FTP\FTPin.txt"

    go

    Please Let me know if there is a better way....

    .

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

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