4 Replies Latest reply on Mar 12, 2012 12:39 PM by Rohit Nayyar

    Invoking NSH functionality from Jython

      Hi everybody!


      I wanted to ask you if you have come around using NSH functionality from within Jython.


      I am currently using:

      Current python/jython version is: 2.5.1 (Release_2_5_1:6813, Sep 26 2009, 13:47:54)

      [Java HotSpot(TM) Server VM (Sun Microsystems Inc.)]


      I.e. I am trying to write to a remote file using Jython and what I currently have is:


      1. This will create a file Example_1 with rw_rw_rw rights on my Windows box. For some reason this call can use the // nsh functionality.

      import subprocess

      subprocess.call(["touch", "//somehostname.domain.com/c/tmp/Example_1"])


      2. This should then write to the file which I just created but doesn't do anything:

      subprocess.call(["echo \"ID-0000\" > //somehostname.domain.com/c/tmp/Example_1"])


      I am running the jython script from within Bladelogic (running as NSH script). The output I get is:

      Error    07.03.2012 08:17:29    OSError: Cannot run program "echo "ID-0000" > //somehostname.domain.com/c/tmp/Example_1" (in directory "/cs/swd/bladelogic/NSH/br"): error=2, No such file or directory


      Eventhough if I run the same command in an NSH here shell from the appserver it will write to the file without any issues.


      Does BMC have a class or something similar which I could import to provide basic NSH functionality from within Jython?


      Thank you very much

        • 1. Re: Invoking NSH functionality from Jython

          Use nexec command to do this . In ur sub process call use nexec. See nexec help for more details.

          There is no class for nsh in python provided.


          What I will do is to create two helper classes to invoke commands. One for local on the appserver and the other based on nexec to run remote commands.




          1 of 1 people found this helpful
          • 2. Re: Invoking NSH functionality from Jython

            The reason

            subprocess.call(["touch", "//somehostname.domain.com/c/tmp/Example_1"])

            is working is because the touch command is only available through NSH, and since NSh in on the path , it works for you .


            But this is not true with echo command, echo is with windows, and that will not understand NSH style paths with full hostname

            So, all you need to do is either create these subprocesses with "nsh -c  <your command in nsh style"


            use nexec in the call to run remote calls if required.





            1 of 1 people found this helpful
            • 3. Re: Invoking NSH functionality from Jython
              Narjit Najran

              subprocess.call(["nsh -c \"echo ID-0000 > //<hostname>/tmp/nn/test_for_gavin"], shell=True)


              works for me and populates the file.

              According to the python docs, the following arguments are taken


              subprocess.call(args, *, stdin=None, stdout=None, stderr=None, shell=False)


              "On UNIX, with shell=True: If args is a string, it specifies the command string to execute through the shell.  If args is a sequence, the first item specifies the command string, and any additional items will be treated as additional shell arguments."

              • 4. Re: Invoking NSH functionality from Jython

                Yes, by using nsh -c you are not letting python to use the windows echo which will never understand //hostname/path - NSH style paths


                So, you can make this as answered !