Created on 02-12-2020 09:23 PM - last edited on 02-12-2020 11:34 PM by VidyaSargur
I am getting below errors while trying to trigger a python script using ExecuteStreamCommand Processor in NiFi. Attaching the screenshot of the properties of the processor. Please help
Below is the error in bulletin board
ExecuteStreamCommand[id=3bc05a73-0170-1000-6f23-80001cc130eb] Failed to process session due to java.io.IOException: Cannot run program "C:\Users\503067805\Desktop\IDP_Project\POC_Well_Path\Trigger_Python_POC\Python\csv_convertion_final.py": CreateProcess error=193, %1 is not a valid Win32 application: org.apache.nifi.processor.exception.ProcessException: java.io.IOException: Cannot run program "C:\Users\503067805\Desktop\IDP_Project\POC_Well_Path\Trigger_Python_POC\Python\csv_convertion_final.py": CreateProcess error=193, %1 is not a valid Win32 application
ExecuteStreamCommand[id=3bc05a73-0170-1000-6f23-80001cc130eb] Could not create external process to run command: java.io.IOException: Cannot run program "C:\Users\503067805\Desktop\IDP_Project\POC_Well_Path\Trigger_Python_POC\Python\csv_convertion_final.py": CreateProcess error=193, %1 is not a valid Win32 application
ExecuteStreamCommand[id=3bc05a73-0170-1000-6f23-80001cc130eb] Failed to process session due to java.io.IOException: Cannot run program "C:\Users\503067805\Desktop\IDP_Project\POC_Well_Path\Trigger_Python_POC\Python\csv_convertion_final.py": CreateProcess error=193, %1 is not a valid Win32 application: org.apache.nifi.processor.exception.ProcessException: java.io.IOException: Cannot run program "C:\Users\503067805\Desktop\IDP_Project\POC_Well_Path\Trigger_Python_POC\Python\csv_convertion_final.py": CreateProcess error=193, %1 is not a valid Win32 application
ExecuteStreamCommand[id=3bc05a73-0170-1000-6f23-80001cc130eb] Could not create external process to run command: java.io.IOException: Cannot run program "C:\Users\503067805\Desktop\IDP_Project\POC_Well_Path\Trigger_Python_POC\Python\csv_convertion_final.py": CreateProcess error=193, %1 is not a valid Win32 application
ExecuteStreamCommand[id=3bc05a73-0170-1000-6f23-80001cc130eb] Failed to process session due to java.io.IOException: Cannot run program "C:\Users\503067805\Desktop\IDP_Project\POC_Well_Path\Trigger_Python_POC\Python\csv_convertion_final.py": CreateProcess error=193, %1 is not a valid Win32 application: org.apache.nifi.processor.exception.ProcessException: java.io.IOException: Cannot run program "C:\Users\503067805\Desktop\IDP_Project\POC_Well_Path\Trigger_Python_POC\Python\csv_convertion_final.py": CreateProcess error=193, %1 is not a valid Win32 application
Created 02-14-2020 09:55 AM
The ExecuteStreamCommand processor is not doing anything fancy here. It is just trying to execute the command you enter. Assuming the command was "myscript.py", The executeStreamCommand would be doing same thing as you would if you opened a terminal window on your NiFi node and clicked on "myscript.py" to run it. Keep in mind that NiFi is performing this action as the user that owns the NiFi java process. The ExecuteStreamCommand processor will pass the FlowFiles content (if there is any) to stdin.
Have you perhaps looked at the ExecuteScript processor instead?
Hope this helps,
Matt
Created 02-13-2020 05:38 AM
If you open a terminal window on your Windows server, can you execute your python script?
If you are not successful from command line, the ExecuteStreamCommand processor is not going to be successful as well.
Thanks,
Matt
Created 02-13-2020 12:07 PM
Hi Mat I can execute the script from spyder (Anaconda) and it is successful. From executestreamcommand processor its not even triggering the script it seems. Its a .py file in the folder. Can this be an issue?
Created 02-14-2020 09:55 AM
The ExecuteStreamCommand processor is not doing anything fancy here. It is just trying to execute the command you enter. Assuming the command was "myscript.py", The executeStreamCommand would be doing same thing as you would if you opened a terminal window on your NiFi node and clicked on "myscript.py" to run it. Keep in mind that NiFi is performing this action as the user that owns the NiFi java process. The ExecuteStreamCommand processor will pass the FlowFiles content (if there is any) to stdin.
Have you perhaps looked at the ExecuteScript processor instead?
Hope this helps,
Matt
Created 02-15-2020 01:09 AM
Hi Matt,
I am able to execute python script from command line. Executescript processor is not an option here because it is an experimental process. I am looking for something more robust which can handle heavy data and also I should be able to put the flow in production. Can you please see the settings in my flow and see if I am doing anything wrong here?
Created 10-19-2021 11:32 AM
The ExecuteScript processor has been around for over 6 years as part of Apache NiFi. It has had many improvements and bug fixes over those years just like many other well used components. I'd be reluctant from calling it "experimental" any longer regardless of what the embedded Apache NiFi docs say.
The only thing to note here is that the ExecuteScript processor does not really execute the "Python" script engine. It is executing "Jython" instead which is a Java implementation of Python. Jython is not 100% compatible with Python, so you must test you script thoroughly.
Thanks,
Matt
Created 02-16-2020 01:11 PM
Hi Matt,
I am able to trigger python script now but stuck on how to pass the output file to STDout so that it can come back to flowfile. Here is what I am trying. STDIN seems to be working fine but STDOUT is not working
f = sys.stdin
reader = csv.reader(f)
***********
##Python code for creating the output file and passing it to STDOUT
xmlfile = open("C:\\Output_from_python\\output_file.xml",'w')
xmlFile.write(doc.toprettyxml(indent = '\t'))
xmlFile.close()
sys.stdout = xmlFile
Created 03-06-2020 10:41 AM
@vikrant_kumar24
You would not configure your python script to write to an XML file on disk
NiFi handles the FlowFile creation in the framework. Any data passed by your Python script to STDOUT will be populated into the content of the resulting flowfile passed to the output stream relationship of the ExecuteStreamCommand processor. Your script does not need to have any awareness of what. FlowFile is or how it is created.
So you simply have your python script send the XML content to STDOUT and NiFi will take care of putting that content in to the FlowFile that will be produced and routed to the "output.stream" relationship of the processor. You can then use the updateAttribute processor the change the filename associated with that content.
Hope this helps,
Matt
Created 10-13-2021 10:52 PM
@vikrant_kumar24 How were you able to run python script in ExecuteStreamCommand? Because I'm also getting the same error.
Created on 02-09-2023 03:11 PM - edited 02-09-2023 03:15 PM
I am having the same problem with head as the command, -1 as the argument, and csv in the content of my flowfile. I read someplace that nifi "lost the state"; what does that mean? I have the flowfile, it has content. Why can't the ESC processor send the first line of the file to the attribute I name?