1 Reply Latest reply: Apr 15, 2013 3:13 AM by 1003034 RSS

    calling script from java code

    852617
      Hi ,


      I have to call the scripts like python,power shell ...... etc from the java code . currently checking the extension of the script calling corresponding method .

      for example if it contains ".py" calling the python . but in future if the script are increased or changed i have to change the code . please help me how to write the generic way .

      if the new scripts are introduced i should able to execute the script .


      public ScriptResponse executeTest(final String scriptName, final List<Tuple<String, String>> list) {
                
                
           if(scriptName.contains(".py")){
                return client.executePython(createScript);
                          
                     }else{
           return client.execute(createScript);
                     }
           
           }

      please help me ............ thanks in advance ...
        • 1. Re: calling script from java code
          1003034
          First of all, you shouldn't check script't extension with .contains() method. I guess in this case "script.py" and "call.pyre.exe" could be both interpreted as Python scripts. Use rather String.endsWith() method.

          The second thing is that if your application is going to be so generic that its re-compilations and updates will get you in trouble, simply force specifying script interpreters together with script names. For example, change implementation from guessing what should be called with "script.py" to plain invoking of "python script.py".

          Another way will be probably dealing with the properties files, explained here: http://docs.oracle.com/javase/tutorial/essential/environment/properties.html

          In these properties files you could store all your supported interpreters against script extensions, like "python=.py", etc.

          Edited by: 1000031 on Apr 15, 2013 11:13 AM