473,396 Members | 1,703 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,396 software developers and data experts.

Calling Executables from SQL Server and getting return value.

Hi All,

I have a requirement of calling a Executable from SQL Server.
I know we can use -

EXEC @result = Master..xp_cmdshell @<command_string>

However I want to get the return value (int) from the executable.
xp_cmdshell always returns 0 or 1. How can the executable return code
say 99 be obtained in SQL Server?

Thanks & Regards,
Chandra Mohan
Jul 20 '05 #1
1 8036
This is a bit of a kludge, but one method is to execute your application
via a CMD file and ECHO the %ERRORLEVEL% so that it is returned in the
xp_cmdshell resultset for subsequent interrogation. For example

MyApp.cmd

@MyApplication.EXE
@ECHO APPLICATION RETURN CODE=%ERRORLEVEL%

SQL script:

SET NOCOUNT ON
DECLARE @ReturnCode int
DECLARE @ApplicationReturnCode int
CREATE TABLE #Messages(Message nvarchar(255))
INSERT INTO #Messages
EXEC @ReturnCode = master..xp_cmdshell 'c:\MyApp\MyApp.cmd'
SELECT @ApplicationReturnCode =
CAST(SUBSTRING(Message, 25, 10) AS int)
FROM #Messages
WHERE LEFT(Message, 24) = 'APPLICATION RETURN CODE='
SELECT
@ReturnCode,
@ApplicationReturnCode
DROP TABLE #Messages
GO

--
Hope this helps.

Dan Guzman
SQL Server MVP

-----------------------
SQL FAQ links (courtesy Neil Pike):

http://www.ntfaq.com/Articles/Index....partmentID=800
http://www.sqlserverfaq.com
http://www.mssqlserver.com/faq
-----------------------

"Chandra Mohan" <bs************@yahoo.com> wrote in message
news:bb************************@posting.google.com ...
Hi All,

I have a requirement of calling a Executable from SQL Server.
I know we can use -

EXEC @result = Master..xp_cmdshell @<command_string>

However I want to get the return value (int) from the executable.
xp_cmdshell always returns 0 or 1. How can the executable return code
say 99 be obtained in SQL Server?

Thanks & Regards,
Chandra Mohan

Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: R.G. Vervoort | last post by:
I am using a javafunction (onclick in select) in which i am calling a function in php (thats why i send this to both php and javascript newsgroups). in the onclick i call the function...
2
by: Eyal | last post by:
Hey, I would appriciate if anyone can help on this one: I have a java object/inteface having a method with a boolean parameter. As I'm trying to call this method from a javascript it fails on...
7
by: Ravi J | last post by:
What is the best way to transfer files between two .NET executables? I have a service, and a client program. Client asks service for data. The service creates one, and passes it back to client....
3
by: Rajesh | last post by:
Hi, I am using iplanet webserver 4.1. I want to call a java class from ssjs file. But I am not getting the result. I have created a java class file and put it in the folder...
0
by: Cleo | last post by:
Hi, I am trying to call a WebService Method written in Weblogic from VB.NET and I am getting the following error. I am using SOAP Caal s from VB.NET. Please find the wsdl file and my code. ...
3
by: Jerome Cohen | last post by:
AI am trying to call a third-party web service. this service expects an XML fragment that contains the request plus other parameter. adding the web reference created the syntax below(reference.vb)....
4
by: sck10 | last post by:
Hello, I am trying to call a function (c#) from the repeater tool and I am not sure if I am calling the function correctly (since I am not getting the results that I want). Using...
12
by: Light | last post by:
Hi all, I posted this question in the sqlserver.newusers group but I am not getting any response there so I am going to try it on the fine folks here:). I inherited some legacy ASP codes in my...
4
by: raghuvendra | last post by:
Hi I have a jsp page with 4 columns: namely Category name , Category order, Input field and a submit button. All these are aligned in a row. And Each Category Name has its corresponding Category...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...

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.