sql-server – 从XP_CMDSHELL获取结果
我一直在搜索网页,似乎只有获取XP_CMDSHELL的结果才能将它们存储到临时表中.真的没有办法吗?
专家交流:
和… 虽然@result仅从xp_cmdshell获取返回值,但您可能可以捕获结果 因人而异… set nocount on declare @filepath varchar(255),@cmd varchar(255),@rc int select @filepath = 'c:temp' select @cmd = 'dir ' + @filepath + '~*.tmp' create table #output (output varchar(255) null) insert #output exec @rc = master..xp_cmdshell @cmd select * from #output where output is not null drop table #output 解决方法从xp_cmdshell捕获STDOUT / STDERR反馈没有更简单的方法;至少有一个选择,但是它不能被分类为更容易:可以将命令的输出重定向到文本文件作为命令的一部分,然后使用OPENROWSET读取文本文件. 在上面发布的脚本中至少有一个错误. ... create table #output (id int identity(1,1),output nvarchar(255) null) insert #output (output) exec @rc = master..xp_cmdshell @cmd select * from #output where output is not null order by id drop table #output (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |