Issue with Command_Line parameters in Windows

Lovelace:

                   - type: button
                     entity: sensor.centralina_irrigazione
                     style:
                       left: 17%
                       top: 37%
                       #--iron-icon-height: 30px
                       #--iron-icon-width: 30px              
                     icon: 'mdi:radio'
                     tap_action:
                       action: call-service
                       service: script.water_a_zone
                       service_data:
                         zona: 1
                         minuti: 5

Script:

water_a_zone:
  alias: Innaffia una zona
  sequence:
   - service: shell_command.run_netro
     data_template:
        zona_val:  >
            {{zona}}
        minuti_val: >
            {{minuti}}

shell_command:

run_netro: python C:\GoogleHome\Python\NetroRun.py {{zona_val}} {{minuti_val}}

When I try to run, I got the following error:


2020-04-10 17:24:55 ERROR (MainThread) [homeassistant.components.shell_command] Error running command: `python C:\GoogleHome\Python\NetroRun.py {{zona_val}} {{minuti_val}}`, return code: 2

Adding logs into the shell_command/init.py I can see:

rendered_args=C:\GoogleHome\Python\NetroRun.py 1 5
args=C:\GoogleHome\Python\NetroRun.py {{zona_val}} {{minuti_val}}

But still I got error:

2020-04-10 17:24:55 ERROR (MainThread) [homeassistant.components.shell_command] Error running command: python C:\GoogleHome\Python\NetroRun.py {{zona_val}} {{minuti_val}}, return code: 2

take a look at this (imho similar) case.
you probably need to escape your backslashes (or replace them with forward slashes).

I don’t think this is the problem… If I put the values instead of the templates in the shell_command… it works like a charm!!!

Moreover rendered_args looks fine!!!

I think the problem is here shlex.split(rendered_args)

This function maybe it’s not compatible with Windows…

It’s completely up to you. The OP from the linked topic has exactly the same symptoms - his hardcoded commands did work just fine :wink:

@AhmadK using the forward slashes worked!!! Thanks a lot!!

1 Like

That’s great!

Please mark a post with a solution by ticking the checkbox next to it.
I will show your post as Solved and a link to the solution post right below your question so future readers could find it easily.