If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Microsoft SQL Server > xp_cmdshell return different value on different SQL

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-08-04, 04:03
benky benky is offline
Registered User
 
Join Date: Apr 2004
Posts: 1
Question xp_cmdshell return different value on different SQL

Hi,
i tried execute script

declare @r int
exec @r=master..xp_cmdshell 'dir c:\blabla.txt'
select @r as 'RESULT'

on SQL7 SP4 (WinNT4), SQL2000(W2000) and SQL2000 SP3 (W2003) but i got different result.

There was result 2 for SQL7 and result 1 for SQL2000.

xp_cmdshell would return only 0(success) and 1(failure). But what does it mean result 2 in case SQL7?

Is there any bug in SQL7?

Thank you for your answer.
Reply With Quote
  #2 (permalink)  
Old 04-08-04, 11:30
Brett Kaiser Brett Kaiser is offline
Window Washer
 
Join Date: Nov 2002
Location: Jersey
Posts: 10,322
Nope, I get 2


SQL 2k, WIN Serv 2k....
__________________
Brett
8-)

It's a Great Day for America everybody!

dbforums Yak CorralRadio 'Rita
dbForums Member List
I'm Good Once as I ever was

The physical order of data in a database has no meaning.
Reply With Quote
  #3 (permalink)  
Old 04-08-04, 11:54
rdjabarov rdjabarov is offline
Registered User
 
Join Date: Jul 2003
Location: San Antonio, TX
Posts: 3,634
If you're looking for return codes and are trying to get it consistent regardless of the platform, try to use a temp table rather than a variable:

insert #tmp exec master.dbo.xp_cmdshell '...'

Then query the table for the result. But since SP3 is well established by now I'd recommend to pick a different method of accessing File System objects. You can use WMI interface for it via sp_OAxxx extended stored procedures.
Reply With Quote
  #4 (permalink)  
Old 04-08-04, 13:09
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 13,599
They are kind of sneaky little beggars, and you have to read between the lines to discover just how sneaky they really are. If you check the destructions for xp_cmdshell very carefully, you'll see a one line comment at the top that reads:
Quote:
Note When executing xp_cmdshell with the Microsoft® Windows® 98 operating systems, the return code from xp_cmdshell will not be set to the process exit code of the invoked executable. The return code will always be 0.
The value returned by xp_cmdshell is actually the final executable return code (ERRORLEVEL) returned to the command interpreter.

-PatP
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On