Search code examples
pythoncmdsubprocessknime

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:

When I run the python file, it opens the Knime exe, after some seconds the knime GUI is also opened. Unfortunately, the exe is not excuting the workflow (for testing the workflow should read an csv file and save it in another file destination)

This is actual code in 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):

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!


Solution

  • I think you made a mistake with the -application part, they should be in different Strings. Also the -workflowDir= C:/... seems to have an extra space too.

    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.

    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.)