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 MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

xp_cmdshell

Status
Not open for further replies.

nancyd1111

Technical User
Sep 7, 2005
9
US
Hi,

I am trying to erase a file using xp_cmdshell and my filename is stored in a variable. Can you tell me how I allow xp_cmdshell to interpret my filename instead of taking it as a literal?

Thanks in advaince!

-------------------------------------------------------

set @filename = N'\\AUTOPILOT\cdrive\Trace\Trace_' + @PlanName + '.trc'

Print @filename
exec master..xp_cmdshell 'erase @filename'

The message displayed is:
Could Not Find C:\WINDOWS\system32\@filename
 
Does this work???


exec master..xp_cmdshell 'erase ' + @filename


-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Seems like the xp_cmdshell is a little finicky. Try this...

Code:
set @filename    = N'\\AUTOPILOT\cdrive\Trace\Trace_' + @PlanName + '.trc'

[red]Declare @Command VarChar(1000)
Set @Command = 'Erase ' + @FileName[/red]
Print @filename
exec master..xp_cmdshell  [red]@Command[/red]

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
you're welcome.


-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top