Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

XP_CMDSHELL and variables

666 views
Skip to first unread message

William Enloe

unread,
Jan 9, 2004, 12:40:56 PM1/9/04
to
Does anyone know how to set up xp_cmdshell to use variable names within
a procedure?

I have declared and set DOS statements within a procedure, but when I
attempt execute xp_cmdshell using the variable the statement errors out.
(See sample code below)
--start TSQL
declare @dos_statement varchar(32)
set @dos_statement = 'mkdir c:\Test\'

xp_cmdshell @dos_statement

--end TSQL

error is:
Server: Msg 170, Level 15, State 1, Line 4
Line 4: Incorrect syntax near 'xp_cmdshell'.

Aaron Bertrand - MVP

unread,
Jan 9, 2004, 12:52:32 PM1/9/04
to
You need to EXEC a procedure, not just state it's name.

EXEC master..xp_cmdshell @dos_statement

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/


"William Enloe" <willia...@domail.maricopa.edu> wrote in message
news:3FFEE7A8...@domail.maricopa.edu...

Aaron Bertrand - MVP

unread,
Jan 9, 2004, 12:57:43 PM1/9/04
to
> You need to EXEC a procedure, not just state it's name.

Cripes, my English professor would have a field day on that one.


Trey Walpole

unread,
Jan 9, 2004, 1:01:46 PM1/9/04
to
unless the procedure is "name"...

EXEC name

;)

"Aaron Bertrand - MVP" <aa...@TRASHaspfaq.com> wrote in message
news:u$rKGpt1D...@tk2msftngp13.phx.gbl...

Jorge Lavado

unread,
Jan 9, 2004, 1:01:22 PM1/9/04
to
hi.

declare @dos_statement varchar(32)
set @dos_statement = 'mkdir c:\Test\'

EXEC MASTER..xp_cmdshell @dos_statement


Karthik

unread,
Jan 9, 2004, 1:06:14 PM1/9/04
to
Use exec before your sp

exec xp_cmdshell @dos_statemen

----- William Enloe wrote: -----



Does anyone know how to set up xp_cmdshell to use variable names within
a procedure?

I have declared and set DOS statements within a procedure, but when I
attempt execute xp_cmdshell using the variable the statement errors out.
(See sample code below)
--start TSQL
declare @dos_statement varchar(32)
set @dos_statement = 'mkdir c:\Test\'

xp_cmdshell @dos_statemen

William Enloe

unread,
Jan 9, 2004, 2:02:01 PM1/9/04
to
Thanks for the replies. I don't know why I didn't try that, except that
my head may have been in the clouds when I was writing this procedure.
I appreciate everyones responses.

Thanks

Aaron Bertrand - MVP

unread,
Jan 9, 2004, 2:11:05 PM1/9/04
to
> my head may have been in the clouds

I can certainly imagine worse places for it to be. :-)

0 new messages