473,473 Members | 1,886 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 33174
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Terri | last post by:
I'm using xp_cmdshell to output a text file from a trigger like this CREATE TRIGGER ON tblApplications FOR INSERT AS DECLARE @FirstName varchar(75) DECLARE @LastName varchar(75) Declare...
5
by: Narine | last post by:
Hi Folks, I am using an xp_cmdshell sp to start a C# app. This app downloads data files and imports them into DB. It has a logging functionality built-in and when executed from the command line...
4
by: Lauren Quantrell | last post by:
I have created the following trigger: CREATE TRIGGER ON OutputTable FOR INSERT AS Declare @filename nvarchar(35) Declare @filecontents nvarchar(2000) Declare @strcmdshell varchar(150)
3
by: Me | last post by:
hi, I have this file I need to execute from an ASP client. since we have installed it on the SQL Database server machine, I thought I could run it like this: Set Cn =...
4
by: Chris Allison | last post by:
I am getting the following error when running a command in Query Analyzer. Msg 50001, Level 1, State 50001 xpsql.cpp: Error 5 from CreateProcess on line 675 Here is the command that I am...
7
by: Terri | last post by:
I have a stored procedure that creates an xml file. It executes a SELECT statement with the FOR XML clause and then writes the xml file using bcp and xp_cmdshell. I am calling this procedure by...
2
by: tolcis | last post by:
Hi! I have a batch file (.bat) that I need to execute inside my stored procedure (SQL 2000). I am trying to call that batch file using xp_cmdshell command. I am probably not using it the right...
1
by: leescriven | last post by:
Hi, Thi is my first post on this forum, and I'm hoping that there is a guru out there who can help me with an annoying problem I am having. I have written a Stored Procedure that relies heavily...
3
by: SJM | last post by:
Howdy, hope someone can help me out with this. I want to run a job each night that copies files from one server to another. I cant even get a simple copy one file from one directory to another,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.