Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

Running a python script through a windows batch file using ExecuteStreamCommand NIFI

avatar
New Contributor

I understand that this question may have been repeated many times before - I am new to Nifi and unfortunately none of the previous answers worked for me. 

 

I am trying to run a simple python script using the ExecuteStreamCommand processor (in Windows 10). However, I cannot call the python script directly from Nifi as it requires the conda environment to be activated (it gives me an import error for python packages- the same happens when the script is called from both nifi and command prompt).

 

I have since written a basic batch script to activate the conda environment and run the python script (see below).

 

file: activate,bat

CALL conda activate base

python sample.py

CALL conda deactivate

 

This works well and produce the output I need when run from the command line. However, calling the bat file from Nifi does not seem to do anything. It does not generate an error (simply pass the incoming flowfile to output with the working directory added to each line of the incoming csv file).

 

The config in Nifi:

Command Arguments: C:\Temp\activate.bat

Command Path: C:\Windows\System32\cmd.exe

I have wasted too much time to find a fix for this. Any help would be greatly appreciated. 

2 REPLIES 2

avatar
New Contributor

This worked for me!

 

cmd "/c activate [my_env] && python my_script.py && deactivate"

 

Source: https://stackoverflow.com/questions/24678144/conda-environments-and-bat-files

 

Still not sure what the underlying issue was ....

avatar
Master Guru

Command path:   C:\Temp\activate.bat

 

get rid of the rest