1 Reply Latest reply on Apr 15, 2013 8:13 AM by 1003034

    calling script from java code

      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) {
                return client.executePython(createScript);
           return client.execute(createScript);

      please help me ............ thanks in advance ...
        • 1. Re: calling script from java code
          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