title: Custom Processor NiFi: How to use session.read with a long running external process
body: <p>I am trying to make a custom processor that read a FlowFile as input and call an external process (as <code>ExecuteStreamCommand</code> does), but I would like to make a batch duration time that after that amount will be sent out the results as a new flowfiles (as <code>ExecuteProcess</code> does). </p>
  
  <p>So I am trying make a mix of these two processors, but I am stuck, because I cannot properly get the grip of <code>session.read()</code> combined with <code>getInputStream()</code>. </p>
  
  <p>Here's what I did with my <code>NewProcessor.java</code> file: 
  - At the beginning of <code>onTrigger</code> I get the flow file session with </p>
  
  <pre><code>FlowFile inputFlowFile = session.get();
          if (null == inputFlowFile) {
              return;
          }
  </code></pre>
  
  <ul>
  <li><p>Then I create a new Flowfile having as parent the incoming flowfile:</p>
  
  <p>FlowFile flowFile = session.create(inputFlowFile);</p></li>
  <li><p>I use the <a href="https://github.com/apache/nifi/blob/c15876494a7fb9ea5eb6cacf02a6ee5f46faa333/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ExecuteProcess.java#L317" rel="nofollow noreferrer"><code>launchProcess</code></a> function taken from the <code>ExecuteProcess</code> in order to run the external process wrapped in a <code>Future</code> so I can call it after the <code>Batch</code> period</p></li>
  <li><p>Here is where it gets tricky to me - I would need a <code>session.read</code> to read from InputFlowfile as <code>ExecuteStreamCommand</code> does <a href="https://github.com/apache/nifi/blob/c15876494a7fb9ea5eb6cacf02a6ee5f46faa333/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ExecuteStreamCommand.java#L486" rel="nofollow noreferrer">here</a> in a <a href="https://github.com/apache/nifi/blob/c15876494a7fb9ea5eb6cacf02a6ee5f46faa333/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ExecuteStreamCommand.java#L546-L617" rel="nofollow noreferrer"><code>InputStreamCallback</code></a> . But since it is tightly linked with the <code>session.write()</code> I don't know how to correctly separate them to make my external process read from the incoming flowfile.</p></li>
  </ul>
  
  <p>Can Someone give me some hint? </p>