RMI using XP_cmdshell

  • Hi,

    I want to run jar file which is reside on remote server using Xp_cmdshell. I tried the following approach , but it is not able to succeed.

    xp_cmdshell "cd RMI

    xp_cmdshell set path=c:\jdk1.6.0_10\bin

    xp_cmdshell 'java RmiClient 172.10.3.114 3232 java -jar /Users/laser/Desktop/RMI/XML_Creator.jar'"

    But it gives error as,

    Server: Msg 103, Level 15, State 7, Line 1

    The identifier that starts with 'cd

    xp_cmdshell cd RM

    xp_cmdshell set path=c:\jdk1.6.0_10\bin

    xp_cmdshell 'java RmiClient 172.10.3.114 3232 java -jar ' is too long. Maximum length is 128.

    Any one help on this.

    Thanks in advance.

    RAVI

  • How about putting everyting into a .BAT or .CMD file.

    Then you can try it out outside sp_cmdshell in a Windows command window.

    As for the way you invoke a jar file, it doesn't look right to me.

    And there is no starting class specified so I presume you know it will try to look it up in the jar manifest.

  • Each time you call xp_cmdshell you create a CMD environment. When xp_cmdshell ends this environment is destroyed. This means that each of your xp_cmdshell statements runs in complete isolation to all other xp_cmdshell statements.

    You need to follow the previousd advice and create a .bat file that contains all the commands you need. This can be tested outside of SQL Server to make sure it works.

    When everything runs OK, then call your .BAT file from xp_cmdshell and troubleshoot any new issues that arise. It is not unusual to have permissions errors when you set this up for the first time.

    Original author: https://github.com/SQL-FineBuild/Common/wiki/ 1-click install and best practice configuration of SQL Server 2019, 2017 2016, 2014, 2012, 2008 R2, 2008 and 2005.

    When I give food to the poor they call me a saint. When I ask why they are poor they call me a communist - Archbishop Hélder Câmara

  • and yet another way ... using some good old fashioned DOS within SQL:

    declare@cmdvarchar(1024)

    select @cmd='"' +

    'F:' + '&&' +--> drive letter to go to

    'cd RMI' + '&&' +

    'set path=c:\jdk1.6.0_10\bin' + '&&' +

    'java RmiClient 172.10.3.114 3232 java -jar /Users/laser/Desktop/RMI/XML_Creator.jar' +

    '"'

    --print @cmd--> for debugging

    exec master..xp_cmdshell @cmd

    RegardsRudy KomacsarSenior Database Administrator"Ave Caesar! - Morituri te salutamus."

  • oh the following:

    @cmd='"' +

    is single quote double quote single quite

    and

    '"'

    is also is single quote double quote single quite

    It's kind of hard to see on the post

    RegardsRudy KomacsarSenior Database Administrator"Ave Caesar! - Morituri te salutamus."

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply