April 29, 2008 at 8:44 am
I'm trying to use the xp_cmdshell system stored procedure to recall an external executable file that have three parameters : the first two parameters are string, the third one is an integer.
Running the exe file from the DOS prompt all works fine, running the exe file from my stored using the xp_cmdshell doesn't work.
I probably don' t use the correct syntax for the third parameter but I can't find the right solutions.
This is my code :
declare @Cmdstr as varchar(8000)
set @cmdstr='"C:\Program Files\KeyGen\vgenlic.exe" pippo pppppp ' + cast (3 as varchar)
DECLARE @result int
EXEC @result=xp_cmdshell @cmdstr
IF (@result = 0)
PRINT 'Success'
ELSE
PRINT 'Failure'
Could someone help me to solve the problem ?
Michela
April 29, 2008 at 8:55 am
It should work as you've pasted in. I get a command string of:
"C:\Program Files\KeyGen\vgenlic.exe" pippo pppppp 3
If that runs from a command prompt, it should work. I'd perhaps grab the return code from a execution (exec @return = xp_cmdshell...") and see what's there. Are you sure the SQL Service account can run this? rights to the folder/file?
April 29, 2008 at 12:37 pm
In SQL 2005, running xp_cmdshell is turned off by default. Have you turned it on?
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
April 30, 2008 at 12:59 am
Thanks for the reply
I already used xp_cmdshell with other commands and always worked fine without problems.
I already tried to have back the return code from the execution and if I write just the first two parameters it seems that the command is executed correctly but if if I add the third one the command always fails.
April 30, 2008 at 12:39 pm
Have you tried copy-and-pasting the value of the @cmdstr variable into the shell and running it that way? Or have you typed it in yourself? (I see that you tested it, I'm asking about methodology here.)
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Viewing 5 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy