how to direct the output of master.dbo.xp_cmdshell to a table

Hi,

is this possible? eg to get a dir listing
master.dbo.xp_cmdshell 'DIR /B "D:\mypath\"'
..and then send this list to a table.

one PAQ suggests it is (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/Q_21413555.html?sfQueryTermInfo=1+dir+get)

Thanks!
xeniumAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
looks like I posted with a space between the / and the C ...

insert into #temp_table
exec master.dbo.xp_cmdshell 'cmd /c DIR /B "D:\mypath\"'
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
please check out this:

insert into #temp_table
exec master.dbo.xp_cmdshell 'cmd / c DIR /B "D:\mypath\"'

0
 
xeniumAuthor Commented:
Ooops, the link given in my question is now working!

AngelIII, btw the 'cmd/ c' seems to cause a problem (the DIR does not exec, only the dos prompt), but the original solution now seems to work:

insert into #temp_table
exec master.dbo.xp_cmdshell 'DIR /B "D:\mypath\"'
0
 
xeniumAuthor Commented:
Great, thanks, this works too.
0
All Courses

From novice to tech pro — start learning today.