Invoking Python scripts from Camunda

I want to call Python programs from Camunda. I have a very simple process here where the process step calls the Python program (see script below).

image

Since I’m using Python3 I can’t use Jython, because this only supports Python2. I managed to start a Python3 program invoking Python from a groovy script. This works, but would there be a more straightforward solution?

def pmdCommand = "/usr/local/bin/python3.7 /users/harmprins/Documents/CamundaWorkflows/scrolledtext.py"

def sout = new StringBuffer()
def serr = new StringBuffer()

def process = pmdCommand.execute()
process.consumeProcessOutput(sout, serr)
process.waitForProcessOutput()

System.out << sout.toString()
1 Like

Not one that I can think of. In either Java or Groovy, I would do just as you are doing.

I suppose if you wanted to get really, really ambitious, you could try to make Python one of the accepted “scripting” languages, but I’ve no idea how to do that and would predict it to be very difficult.

Personally, I’d rewrite the Python in Java or Groovy.

The post seems to have been withdrawn, but I’ll answer anyway.

Setting a variable in Groovy is very straightforward as shown in this example:

execution.setVariable(“loadReturnValue”, “1”);

I figured it out already, that’s why I deleted the post (see other post), but thanks anyway.

Hi Harm,
Can you please post the solution here

Here’s the solution I posted earlier:

    def pmdCommand = "/usr/local/bin/python3.7 /users/harmprins/Documents/CamundaWorkflows/scrolledtext.py"

    def sout = new StringBuffer()
    def serr = new StringBuffer()

    def process = pmdCommand.execute()
    process.consumeProcessOutput(sout, serr)
    process.waitForProcessOutput()

    System.out << sout.toString()