Clarity

 View Only

 GEL Script Output Shell Script to LOG

Jump to Best Answer
Feras Khatib's profile image
Feras Khatib posted May 03, 2022 07:39 PM
I've got a pretty basic gel script developed strictly to call a shell script, and that shell script has a few commands to encrypt a file. When I run the shell script alone, it works completeley fine. When I run it in Clarity via process, that step hangs and doesn't give me any type of message or error. I am looking at how I can capture the output of a shell script to see what is happening when running the shell script via a process. 

<gel:script xmlns:core="jelly:core" xmlns:file="jelly:com.niku.union.gel.FileTagLibrary" xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary"
  xmlns:soap="jelly:com.niku.union.gel.SOAPTagLibrary" xmlns:sql="jelly:sql" xmlns:xog="http://www.niku.com/xog"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <gel:log level="info" message="Process execution started..."/>
  <core:invokeStatic className="java.lang.Runtime" method="getRuntime" var="javaRuntime"/>
  <core:set value="encrypt.sh filename" var="myArgs"/>
  <core:invoke method="exec" on="${javaRuntime}" var="execBAT">
    <core:arg type="java.lang.String" value="${myArgs}"/>
  </core:invoke>
  <core:invoke method="waitFor" on="${execBAT}" var="waitBAT"/>
  <gel:log level="info" message="Process execution ended..."/>
</gel:script>​


I am guessing it has something to do with the java command I am running to trigger the encryption in the shell script, or a reference to a a variable/directory that's off. 

Feras Khatib's profile image
Feras Khatib Best Answer
Figured it out with help from support using the ProcessBuilder class

<core:set value="encrypt.sh" var="scriptName"/>
  <core:set value="file_name" var="arg1"/>
  <gel:log level="info" message="Process execution started. Encrypting Fieldglass file: ${arg1}"/>
  <!-- Set up String class to pass to array -->
  <core:invokeStatic className="java.lang.Class" method="forName" var="stringClass">
    <core:arg type="java.lang.String" value="java.lang.String"/>
  </core:invokeStatic>
  <!-- make a 1D array of objects needed for invoke(obj, string...) call -->
  <core:invokeStatic className="java.lang.reflect.Array" method="newInstance" var="stringArray">
    <core:arg type="java.lang.Class" value="${stringClass}"/>
    <core:arg type="int" value="${2}"/>
  </core:invokeStatic>
  <!-- assign the array items -->
  <core:invokeStatic className="java.lang.reflect.Array" method="set">
    <core:arg type="java.lang.Object" value="${stringArray}"/>
    <core:arg type="int" value="${0}"/>
    <core:arg type="java.lang.Object" value="${scriptName}"/>
  </core:invokeStatic>
  <core:invokeStatic className="java.lang.reflect.Array" method="set">
    <core:arg type="java.lang.Object" value="${stringArray}"/>
    <core:arg type="int" value="${1}"/>
    <core:arg type="java.lang.Object" value="${arg1}"/>
  </core:invokeStatic>
  <!-- create builder -->
  <core:new className="java.lang.ProcessBuilder" var="builder">
    <core:arg value="${stringArray}"/>
  </core:new>
  <gel:log level="info" message="ProcessBuilder array ${stringArray}"/>
  <!-- start the script -->
  <core:invoke method="start" on="${builder}" var="proc"/>
  <gel:log level="info" message="Process execution ended..."/>​