简体   繁体   English

在Python中使用多个参数执行Knime(subprocess.run)

[英]Execute Knime with multiple arguments in Python (subprocess.run)

Hello all , 大家好

i'm looking for a way to execute a KNIME workflow in Python in batch mode (without opening the GUI of KNIME, https://www.knime.com/faq#q12 ) After hours of trying I am asking you whether you can help me in this case: 我正在寻找一种以批处理模式在Python中执行KNIME工作流的方法(无需打开KNIME的GUI, https ://www.knime.com/faq#q12)经过数小时的尝试,我问您是否可以在这种情况下可以帮助我:

When I run the python file, it opens the Knime exe, after some seconds the knime GUI is also opened. 当我运行python文件时,它会打开Knime exe,几秒钟后还会打开knime GUI。 Unfortunately, the exe is not excuting the workflow (for testing the workflow should read an csv file and save it in another file destination) 不幸的是,exe并没有执行工作流程(为了测试工作流程,应读取一个csv文件并将其保存在另一个文件目标位置)

This is actual code in python 3.7: 这是python 3.7中的实际代码:

import subprocess
subprocess.run(["C:/Program Files/KNIME/knime.exe","-consoleLog","-nosplash","-noexit","-nosave","-reset","-application org.knime.product.KNIME_BATCH_APPLICATION","-workflowDir= C:/Users/jssch/knime-workspace/testexecute"]

When i paste the following code in command line the code is working and is executed correctly (it just hands over the arguments and does not open the knime GUI): 当我在命令行中粘贴以下代码时,该代码正在工作并正确执行(它只是移交参数,而不会打开knime GUI):

C:\Program Files\KNIME\knime.exe" -consoleLog -noexit -nosplash -nosave -reset -application org.knime.product.KNIME_BATCH_APPLICATION -workflowDir="C:\Users\jssch\knime-workspace\testexecute"

Thanks for your help in advance! 谢谢您的帮助!

I think you made a mistake with the -application part, they should be in different Strings. 我认为您在-application部分中犯了一个错误,它们应该使用不同的Strings。 Also the -workflowDir= C:/ ... seems to have an extra space too. 而且-workflowDir= C:/ ...似乎也有多余的空间。

The problematic part: 问题部分:

"-application org.knime.product.KNIME_BATCH_APPLICATION"

it should be: 它应该是:

"-application", "org.knime.product.KNIME_BATCH_APPLICATION"

Probably you do not want the -noexit argument either. 可能您也不想使用-noexit参数。

All together: 全部一起:

import subprocess
subprocess.run(["C:/Program Files/KNIME/knime.exe", "-consoleLog", "-nosplash", "-nosave", "-reset", "-application", "org.knime.product.KNIME_BATCH_APPLICATION", "-workflowDir=C:/Users/jssch/knime-workspace/testexecute"]

(I usually prefer the paths without spaces, strange characters, I would use a KNIME installation from a different path, though this is fine too.) (我通常更喜欢没有空格,奇怪字符的路径,我会从其他路径使用KNIME安装,尽管这也很好。)

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

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