469,090 Members | 1,183 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,090 developers. It's quick & easy.

xp_cmdshell and pass command line parameters to .exe file

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
Jul 20 '05 #1
1 30618
db********@yahoo.com (Dan Bart) wrote in message news:<fa**************************@posting.google. com>...
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


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
Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Terri | last post: by
4 posts views Thread by Chris Allison | last post: by
2 posts views Thread by tolcis | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by kglaser89 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.