简体   繁体   English

使用 ExecuteStreamCommand NIFI 通过 windows 批处理文件运行 python 脚本

[英]Running a python script through a windows batch file using ExecuteStreamCommand NIFI

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.我知道这个问题之前可能已经重复了很多次 - 我是 Nifi 的新手,不幸的是,以前的答案都没有对我有用。

I am trying to run a simple python script using the ExecuteStreamCommand processor (in Windows 10).我正在尝试使用ExecuteStreamCommand处理器(在 Windows 10 中)运行一个简单的 python 脚本。 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).但是,我不能直接从 Nifi 调用 python 脚本,因为它需要激活 conda 环境(它给了我 python 包的导入错误 - 当从 nifi 和命令提示符调用脚本时也会发生同样的情况)。

I have since written a basic batch script to activate the conda environment and run the python script (see below).此后,我编写了一个基本的批处理脚本来激活 conda 环境并运行 python 脚本(见下文)。

activate.bat激活.bat

CALL conda activate base   
python sample.py
CALL conda deactivate

This works well and produces the output I need when run from the command line.这很好用,并在从命令行运行时产生我需要的 output。 However, calling the bat file from Nifi does not seem to do anything.但是,从 Nifi 调用 bat 文件似乎没有任何作用。 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).它不会产生错误(只需将传入的流文件传递给 output,并将工作目录添加到传入的 csv 文件的每一行)。

The config in Nifi: Nifi中的配置:

  • Command Arguments: C:\Temp\activate.bat命令 Arguments: C:\Temp\activate.bat

    Command Path: C:\Windows\System32\cmd.exe命令路径:C:\Windows\System32\cmd.exe

Any help would be greatly appreciated.任何帮助将不胜感激。

This worked for me!这对我有用!

cmd "/c activate [my_env] && python my_script.py && deactivate" cmd "/c 激活 [my_env] && python my_script.py && 停用"

Source: Conda environments and.BAT files来源: Conda 环境和.BAT 文件

Still not sure what the underlying issue was....仍然不确定根本问题是什么......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM