Connecting Tech Pros Worldwide Forums | Help | Site Map

xp_cmdshell and pass command line parameters to .exe file

Dan Bart
Guest
 
Posts: n/a
#1: Jul 20 '05
I need to execute xp_cmdshell in a trigger and pass a command line
parameter to the .exe program

i.e. I have a .exe program c:\program files\savedata.exe

In the trigger I have a parameter @Id bigint

I need to pass the parameter @Id to savedata.exe

In the trigger, I am trying

EXEC master..xp_cmdshell 'cmd.exe /C "c:\program files\savedata.exe "'
+ CAST(@Id as varchar)

BUT this does not work.

Can someone please help me with how to do this?

Thanks,

db

Simon Hayes
Guest
 
Posts: n/a
#2: Jul 20 '05

re: xp_cmdshell and pass command line parameters to .exe file


dblist2003@yahoo.com (Dan Bart) wrote in message news:<fa87ff30.0311101329.10b9d3fd@posting.google. com>...[color=blue]
> I need to execute xp_cmdshell in a trigger and pass a command line
> parameter to the .exe program
>
> i.e. I have a .exe program c:\program files\savedata.exe
>
> In the trigger I have a parameter @Id bigint
>
> I need to pass the parameter @Id to savedata.exe
>
> In the trigger, I am trying
>
> EXEC master..xp_cmdshell 'cmd.exe /C "c:\program files\savedata.exe "'
> + CAST(@Id as varchar)
>
> BUT this does not work.
>
> Can someone please help me with how to do this?
>
> Thanks,
>
> db[/color]

Calling an external program from a trigger is usually a bad idea - if
the external program takes a long time to run, hangs, or does
something unexpected, you can easily block other clients. A better
plan is to insert your @Id values into a separate table, then have a
scheduled job which processes the values at regular intervals - this
won't block or otherwise impact the main processing.

If you really want to do it, you should rewrite your command like
this:

declare @cmd varchar(8000)
set @cmd = 'cmd.exe /C "c:\program files\savedata.exe "' + CAST(@Id as
varchar)
EXEC master..xp_cmdshell @cmd

Simon
Closed Thread