AnsweredAssumed Answered

Execute bash script from GEL script

Question asked by msnizek on Aug 11, 2015

Hi all,


I have a problem with executing .sh script on application server. We are running on RedHat linux.

Clarity version is:

Java version is: jdk1.7.0_67


The script below works partialy. One part which should create the file works perfect and the file is created (in my case modified, because it already exists because of permissions). But the second part which should execute the does nothing. The process with this script finishes without any error.


My objective is to start the execute.jar with parameters. I also tried to execute directly the jar with parameters, but also without any success (see part of code to execute just the jar)

 <core:invokeStatic className="java.lang.Runtime" method="getRuntime" var="javaRuntime"/>
    <core:set value="java -jar ${location}/export.jar '${proj_code}' '${period}'" var="myArgs"/>
    <core:invoke method="exec" on="${javaRuntime}" var="execBAT">
        <core:arg type="java.lang.String" value="${myArgs}"/>
    <core:invoke method="waitFor" on="${execBAT}" var="waitBAT"/>
    <gel:log category="XOG" level="INFO">myArgs: ${myArgs}, execBAT: ${execBAT}, javaRuntime: ${javaRuntime},waitBAT: ${waitBAT}</gel:log>


Here is my code:


  <gel:setDataSource dbId="Niku"/>
    <!-- parametry -->
    <sql:query escapeText="false" var="parametry">
  par4.c_par_value location
  from odf_ca_c_parameters par4
  where par4.code='jar_location'
  <core:forEach items="${parametry.rows}" var="thisRow">
  <core:set value="${thisRow.location}" var="location"/>
  <sql:query escapeText="false" var="jar_params">
  (select code from inv_investments where id=odf_parent_id) proj_code,
  (select to_char(prstart,'MM-YYYY') from prtimeperiod where prid=c_de_period) period
  from ODF_CA_c_prj_deliv_export where id=${gel_objectInstanceId}
  <core:forEach items="${jar_params.rows}" var="thisRow">
  <core:set value="${thisRow.proj_code}" var="proj_code"/>
  <core:set value="${thisRow.period}" var="period"/>
    <!--- Spuštění batch souboru -->
  <file:writeFile delimiter=" " embedded="false" fileName="${location}/">
    <!-- Print lines to a file-->
    <core:catch var="filerrcreate">
        <file:column value="echo data >> data.txt"/>
        <!-- 0-->
        <file:column value="java -jar ${location}/export.jar '${proj_code}' '${period}'"/>
        <!-- 0-->
      <gel:out>[XOG]File was created.</gel:out>
      <gel:log category="XOG" level="INFO">File was created.</gel:log>
      <core:when test="${filerrcreate != null}">
        <gel:out>File creation failed: ${filerrcreate}</gel:out>
        <gel:log category="XOG" level="ERROR">File creation failed: ${filerrcreate}</gel:log>
        <gel:out>File was created successfully.</gel:out>
        <gel:log category="XOG" level="INFO">File was created successfully.</gel:log>
  <core:invokeStatic className="java.lang.Runtime" method="getRuntime" var="javaRuntime"/>

         <core:set value="sh ${location}/" var="command"/>

         <core:invoke method="exec" on="${javaRuntime}" var="execCommand">
             <core:arg type="java.lang.String" value="${command}"/>



Please have you got any idea how to let it work?


Thanks in advance,