Python script through `execute command`

Hi,

Im using execute command to run python script, works well as expected, but i didn’t find way to dyanmically get stdout from execute command node.

I have to wait for the execute command pass to get the stdout.

have you an idea ?

regards,

Hey @Jeremy_Bepoix, I am not sure I fully understand the question. What does your Execute Command output look like and what would you like it to be instead?

My execute command looks like :
py -3.9 path/to/myscript.py

myscript.py looks like :

<code stuff>
print('exemple_print_a')
<code stuff>
print('exemple_print_b')
<code stuff>
print('exemple_print_c')

output looks good :
exit : 0, stderr:0, stdout:"exemple_print_a, exemple_print_b, exemple_print_c"

BUT, i have to wait the end of execute command process to get all print.
isn’t dynamic

So you’d like the Execute Command node to trigger the workflow execution each time it prints something to stdout? That’s unfortunately not how the node works, it would wait for the respective command to finish.

If you control the script you could consider sending a simple webhook to n8n’s webhook node instead each time it would usually print something. That way, you could trigger a new workflow execution immediately for each webhook.

1 Like

okay, i’ll try another way.

thanks

Hi @Jeremy_Bepoix ,
can you explain about the settings - how do you run your python scripts by the way you described above?
I mean “py -3.9 path/to/the/script”? Is there some manual on how to do the same? I am trying to run the run the script by a schedule. Still no success.
I tried a few variants:
python3 /home/username/project_65970/get_bd_date.py

or

/usr/lib/python3.6/python3 /home/username/project_65970/get_bd_date.py

Every time I receive the error message:

/bin/sh: /usr/lib/python3.6/python3: not found

or

/bin/sh: python3: not found

Hi @Nicolay_Vasiliev, n8n would need to have access to Python in order to run any scripts.

Depending on how you have deployed n8n there are different ways to achieve this. You could for example create a custom Docker image for n8n that installs Python (of you are using Docker in the first place).

Hi @MutedJam,
thanks for your response!

I use n8n via Docker Compose. I have found the topic with a similar context and I still don’t understand which way I need to use exactly

https://community.n8n.io/t/running-python-with-n8n/

So to use Python on my own instance I am using a Dockerfile like this:

FROM n8nio/n8n:latest

ENV PYTHONUNBUFFERED=1
RUN apk add --update --no-cache python3 curl
RUN python3 -m ensurepip
RUN pip3 install --no-cache --upgrade pip setuptools
RUN pip3 install speedtest-cli

My docker-compose.yml file in the same directory then defines n8n like so:

services:
  n8n:
    build: .
    restart: unless-stopped
    environment:
      ...

Now when I run docker pull n8nio/n8n:latest && docker compose build I am building a custom version of n8n including Python:

3 Likes

Hi @MutedJam ,

Thank you very much for such detailed explanation :+1:

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.