Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Store result of xp_cmdshell to variable

Status
Not open for further replies.

NathanGriffiths

Programmer
May 14, 2001
213
NZ
Hi,

I want to put the result of running an xp_cmdshell command into a local variable. Is this possible?

e.g.

execute master..xp_cmdshell 'dir /b d:\Client\Updates\2003\Apr_2003\Data\*19094*.*'

returns;

MRN19094X20030329.csv

Can I somehow store this to a local varchar variable?

thanks in advance,

Nathan
 
I don't think you can put it in a variable but you can insert it into a temp table:

Code:
CREATE TABLE #cmd (txt varchar(1000))

INSERT #cmd
EXEC master..xp_cmdshell 'dir /b d:\Client\Updates\2003\Apr_2003\Data\*19094*.*'

--James
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top