Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2004

    Question Unanswered: xp_cmdshell return different value on different SQL

    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.

  2. #2
    Join Date
    Nov 2002
    Nope, I get 2

    SQL 2k, WIN Serv 2k....

    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.

  3. #3
    Join Date
    Jul 2003
    San Antonio, TX
    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.

  4. #4
    Join Date
    Feb 2004
    In front of the computer
    Provided Answers: 54
    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:
    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.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts