1 Reply Latest reply on Mar 7, 2017 10:35 PM by cfang

    OsCommandBatchlet: run native OS commands in a batch job

    cfang

      We recently implemented a batchlet, OsCommandBatchlet, in jberet-support module.  This batchlet allows you to run native OS commands in a batch job step.

       

      Many tasks can make use of this OsCommandBatchlet to run system commands as an integral part of the batch work flow.  For example,

       

      * split a large text files into multiple smaller files by number of lines, to prepare for partitioned step execution;

      * sort large text files;

      * merge multiple text files;

      * cut text files by columns;

      * generate pdf report files by running acrobat command line tools;

      * any other custom shell scripts or Windows bat scripts.

       

      More details, please see JIRA issue:

      JBERET-292

       

      An example job.xml using OsCommandBatchlet:

       

      <job id="job1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" version="1.0">
        <step id="job1.step1">
        <batchlet ref="osCommandBatchlet">
        <properties>
        <property name="commandLine" value="split -l 200 /Users/cfang/dev/jsr352/jberet-support/src/test/resources/ca2013entities_ascii.txt ca2013entities_part_"/>
        <!--

        <property name="commandArray" value="#{jobParameters['commandArray']}"/>

        -->
        <property name="workingDir" value="#{jobParameters['workingDir']}"/>
        <property name="commandOkExitValues" value="#{jobParameters['commandOkExitValues']}"/>
        <property name="timeoutSeconds" value="#{jobParameters['timeoutSeconds']}"/>
        <property name="environment" value="FOO=1, BAR=a"/>

        <property name="streamHandler" value="org.jberet.support.io.OsCommandBatchletTest$NoopStreamHandler"/>
        </properties>
        </batchlet>
        </step>
      </job>

        • 1. Re: OsCommandBatchlet: run native OS commands in a batch job
          cfang

          As part of the fix to issue

          JBERET-313

          Support custom stream handler in OsCommandBatchlet,

           

          a new batch property is added to OsCommandBatchlet, to set the custom input/output stream handler:

           

          <property name="streamHandler" value="org.jberet.support.io.OsCommandBatchletTest$NoopStreamHandler"/>

           

          The property value is the fully qualified name of a class that implements org.apache.commons.exec.ExecuteStreamHandler, to customize the handling of input and output stream for the OS command subprocess.  For instance, it may filter out certain output text, limit the amount of output data, or ignore all output.  This is useful when the command produces too much output.