473,402 Members | 2,050 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

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 33149
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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,...
0
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...

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.