openhab / openhab-addons

Add-ons for openHAB
https://www.openhab.org/
Eclipse Public License 2.0
1.86k stars 3.56k forks source link

[exec] Unable to use %2$s #2605

Closed paul43210 closed 3 years ago

paul43210 commented 6 years ago

Related to

This bug is related to a discussion in the forums: https://community.openhab.org/t/an-exception-occurred-while-formatting-the-command-line/33385

Expected

It is expected that the value of the String item is replaces the %2$s on the command line of and exec2 Thing.

Issue

As soon as the %2$s is added, the command no longer executes. I experience this error:

2017-08-15 20:07:12.902 [ERROR] [hab.binding.exec.handler.ExecHandler] - An exception occurred while formatting the command line with the current time and input values : ‘Format specifier ‘%2$s’’

Using %1$s works as it adds the date/time as expected.

I have attempted to create things & items using habmin, and actual files with no success. The value of the input string has been set.

Steps and settings

The simplest setting i have tried are:

items/demo.items:String Output4 “Output4 [%s]” (Command) { channel=“exec:command:echo_exec4:output” } items/demo.items:String Input4 “Input4 [%s]” (Command) { channel=“exec:command:echo_exec4:input” } things/demo.things:Thing exec:command:echo_exec4 [command="/bin/echo abc ‘%2$s’", interval=30, autorun=true]

Context

I am trying to replicate behavior of exec1 where there was a separate command for ON, OFF and GET. By using the %2$s, I should be able to pass the state of my switch to the command line.

Your Environment

I am running OpenHAB 2.1.0 Running on Ubuntu xenial. openjdk version "1.8.0_131" OpenJDK Runtime Environment (build 1.8.0_131-8u131-b11-2ubuntu1.16.04.3-b11) OpenJDK 64-Bit Server VM (build 25.131-b11, mixed mode)

pinki commented 6 years ago

I have the same problem.

[hab.binding.exec.handler.ExecHandler] - An exception occurred while formatting the command line with the current time and input values : 'Format specifier '%2$s''

OpenHAB 2.1.0 OpenHAB-AddOns 2.2.0-SNAPSHOT Linux raspberrypi2 4.9.35-v7+ #1014 SMP Fri Jun 30 14:47:43 BST 2017 armv7l GNU/Linux java version "1.8.0_152" Java(TM) SE Runtime Environment (build 1.8.0_152-b16) Java HotSpot(TM) Client VM (build 25.152-b16, mixed mode)

acoulson2000 commented 6 years ago

Same problem here.

CameronDevine commented 6 years ago

There is a link to a jar file in pull request #2671 which fixes this problem. This file can be manually installed in openhab to get the functionality you are looking for.

martinvw commented 6 years ago

Did one of you ever take a look at https://github.com/openhab/openhab2-addons/pull/2012? Does this maybe answer to some of the demands requirments, I can't look into @kgoderis agenda by maybe he would like some help in wrapping that one up.

kgoderis commented 6 years ago

@martinvw I slowly but steadily working through my pending PR. I have not followed all the issues raised wrt Exec as I sense they will be solved by https://github.com/openhab/openhab2-addons/pull/2012

lmicheel commented 5 years ago

Hello, same issue i'm still facing in version 2.4

HarrysLapTimer commented 4 years ago

I'm facing this issue with openHAB 2.5.2. Is it possible this problem is still open?

HarrysLapTimer commented 4 years ago

Update: the problem occurs in case the argument (channel exec:command:XXX:input) is set using postUpdate instead of sendCommand. It looks like the argument is not propagated in this case the the second arg is undefined. From my understanding the argument is just an internal variable and nothing that actually receives a command. It may make sense to handle both cases...

p-dmitrij commented 3 years ago

The same problem for me, OH version: "openHAB 2.5.7-1 (Release Build)". It just throws out the error after each reboot, even if I'm using only "sendCommand" method for updating of the "Input" channel. The only workaround that I found is to change the "Input" channel in the Paper UI (Control) to whatever manually.