sql - Catching Error Message from XP_CMDSHELL -
i running following command:
exec @returncode = master.dbo.xp_cmdshell @cmdline
on results tab 2 lines not find part of path '\server\directory\filename'. null
how capture first line in error message? tried using try catch block "select @errormessage = error_message()" , doesn't grab it.
the message not coming sys.messages. error message coming then?
the error comes command shell itself, not sql server error
one way grab error is
declare @cmdline varchar(500),@returncode int select @cmdline = 'dir f:' create table #temp (somecol varchar(500)) insert #temp exec @returncode = master.dbo.xp_cmdshell @cmdline if @returncode <> 0 select * #temp somecol not null
but of course if dir c: table filled files , folders command
Comments
Post a Comment