Exec binding - Windows parameters in Input problem

Hello,

I creted Exec biniding with .bat command for Windows. Coomand in this binding is defined as “R:_OpenHAB_OpenHAB\conf\misc\string2file.bat”.

Command is calling correctly but parameters which has been defined in “Input” channel (here is the file name as “test.txt” are ignored :frowning:

In docs - “Input that will be passed as second parameter to the command”)

So finally the effect is that “%1” in the bat file is empty :frowning:

What I’m doing wrong?

I dont’t use Windows (nor the Exec binding for that matter…) but from the docs I understand that the second parameter gets the input channel command, not the first:

The following parameters are automatically added:

  • the current date (as java.util.Date, example: %1$tY-%1$tm-%1$td)
  • the current (or last) command to the input channel (see below, example: %2$s)

note - if you trigger execution using interval or the run channel, the %2 substitution will use the most > recent command…

So where I can define 1st parameter in OH? No parameter is passed - neither the first nor the second :frowning:

Can you show the exact configuration? Have you defined the Thing in UI or text configuration?

sure, for thing is:
UID: exec:command:d1797d52e8
label: Command string2file
thingTypeUID: exec:command
configuration:
transform: REGEX((.*))
interval: 0
autorun: false
command: R:_OpenHAB_OpenHAB\conf\misc\string2file.bat
timeout: 15
channels:

  • id: output
    channelTypeUID: exec:output
    label: Output
    description: Output of the last execution of the command
    configuration: {}
  • id: input
    channelTypeUID: exec:input
    label: Input
    description: Input that will be passed as second parameter to the command
    configuration: {}
  • id: exit
    channelTypeUID: exec:exit
    label: Exit Value
    description: The exit value of the last execution of the command
    configuration: {}
  • id: run
    channelTypeUID: exec:run
    label: Running
    description: Send ON to execute the command and the current state tells whether
    it is running or not
    configuration: {}
  • id: lastexecution
    channelTypeUID: exec:lastexecution
    label: Last Execution
    description: Time/Date the command was last executed, in
    yyyy-MM-dd’T’HH:mm:ss.SSSZ format
    configuration: {}

and input channel like on the picture…

You don’t define it anywhere. You just have to add it to your command where it needs to go.

R:_OpenHAB_OpenHAB\conf\misc\string2file.bat %2$s

Pay attention to the examples in the add-on docs:

php ./configurations/scripts/script.php %2$s
 ...
// "%2$s" will be replace by the input channel command, this makes it possible to use one command line with different arguments.
// e.g: "ls" as <YOUR COMMAND> and "-a" or "-l" as additional argument sent to the input channel in the rule.
Thing exec:command:yourcommand [ command="<YOUR COMMAND> %2$s", interval=0, autorun=false ]

Before the command is called,. %2$s is replaced with what ever state the Item linked to the Input Channel currently has or the command that was sent to that Item.

Note the whitelist must match exactly this command so if you add the parameter you’ll have to update the whitelist too.

1 Like

Hello,

thank you very much! I added to whitelist exactly as “string2file.bat %2$s” and it works!

Thank you @rlkoshak!