Search code examples
apache-nifi

how to add output stream relationship result of executestreamcommand processor into original flow file in nifi


I need a help. I am using python script here. I wanted to add output stream relationship result of ExecuteStreamCommand processor into original flow file in nifi


Solution

  • https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-standard-nar/1.9.0/org.apache.nifi.processors.standard.ExecuteStreamCommand/index.html

    check Output Destination Attribute property - if it's empty then all what you print/write to STDOUT will go to flow file content

    in python you could write to stdout using simple print:

    print("hello world") # this will go to file content
    

    or sys module:

    import sys
    
    sys.stdout.write( "Hello Standard Output!\n" )
    

    to append flowfile content - you have to copy from stdin to stdout current file content and then write something new

    import sys
    #write current file content (use buffer for binary mode - python3+
    for chunk in iter(lambda: sys.stdin.buffer.read(4096), b''):
      sys.stdout.buffer.write(chunk)
    
    sys.stdout.buffer.flush()
    #append new data
    sys.stdout.write('new data at the end...')