SQL Server - xp_cmdshell output - Asked By Liviu Anca on 03-May-04 06:31 AM

Hi all,

Is there a simple way to get to the output of an executed xp_cmdshell command ?
I have a stored procedure and from inside it I need to run a PING command and to know if it was successful or not.


try this - Asked By Mike Prince on 03-May-04 07:37 AM

create table #tmp(result varchar(255))
insert into #tmp exec master.dbo.xp_cmdshell 'ping yahoo.com'

if exists(select * from #tmp where result like '%request timed out%')
	print 'timeout'
	print 'reply'

drop table #tmp

xp_cmdshell output - Asked By Claire H on 16-May-04 12:44 AM

You could actually make use > simbol to utput the result into a text file
Here is an example
xp_cmdshell 'ping www.yahoo.com > c:\test.txt'