An exception occurred while formatting the command line

Hi All,

I am having a really hard time with the exec2 binding. I have 2.1.0 configured with the demo setting (option selected right at the start), then i added the exec binding with a basic command to run and print the arguments it gets.

openhab> smarthome:items list | grep exec
exec_command_15de85cfbd2_output (Type=StringItem, State=NULL, Label=Output, Category=null)
exec_command_15de85cfbd2_input (Type=StringItem, State=a123b, Label=Input, Category=null)
exec_command_15de85cfbd2_exit (Type=NumberItem, State=NULL, Label=Exit Value, Category=null)
exec_command_15de85cfbd2_run (Type=SwitchItem, State=OFF, Label=Running, Category=null)
exec_command_15de85cfbd2_lastexecution (Type=DateTimeItem, State=NULL, Label=Last Execution, Category=null)

All the links are setup between the Thing and Items (i set the “simple” option to create them automatically).
Then I set the Input to “a123b”, and the command to:
/…/scripts/openhab ‘%1$s’ '%2$s’
As you can see, the input channel is setup.

Everything works find if I remove the ‘%2$s’ from the command, but if I add it in I get 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’’

Thanks for your help,
Paul

Try dropping the single quotes.

Try just using the %2$s as the argument.

I have tried that as well. Single quotes, double quotes, no quotes, tried
escaping the % and the $ too. No dice. Somehow I think I need to set the
display format in the input string item.

I have now tried using actual items in an .item file:

String Output3 “Output3 [%s]” (Command)
String Input3 “Input3 [%s]” (Command)
Number Exit3 “Exit3 [%.1f]” (Command)
Switch Run3 “Run3” (Command)
DateTime Last3 “Last3 [%1$tH:%1$tM]” (Command)

Still no luck.

Does someone have a working setup for the exec2 module they could provide?

I believe the problem lies in this code.

                    if (lastInput != null) {
                        commandLine = String.format(commandLine, Calendar.getInstance().getTime(), lastInput);
                    } else {
                        commandLine = String.format(commandLine, Calendar.getInstance().getTime());
                    }

The lastInput is null, so the else clause is hit, attempting to format the string with only 1 parameter value, but the format specifier contains 2 parameters.

Does this mean i need to set the “lastInput” ?
Is that the same as my input item?

No, I don’t think so.

It looks to me like this is a defect that’ll have to be fixed in code.

The thing that has me curious is that nobody else is using this module? at all? Seems like a basic functionality.

Lots of people are using exec2 successfully.

I don’t know how many are using the %2 argument though. That seems to be the source of your problem.

How do people change the behaviour of the command based on the state of a
switch?

In exec1 I could set three command lines, on, off and get. How do I get
similar behaviour with exec2?

I don’t use exec so can’t fully answer. But I know that lots and lots of people have it working. A search of the forum for “exec %2 shows dozens of examples”.

Are you defining the Things in a .things file or in PaperUI. I’ve only seen people use the .things file so maybe that is part of the problem. Try defining your Things like the examples in the readme docs and see if it will work that way.

I was using Habmin to create all my things/items, but I also tested with actual files. My latest settings 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 ‘%1$s’”, interval=30, autorun=true]

It behaves the same way, as soon as I add the ‘%2$s’, I get an error.
@kgoderis has there been updates to the binding since 2.1.0 that may fix this?

[command="/bin/echo abc ‘%1$s’", inter

val=30, autorun=true]

Try dropping the single quotes.

Try replacing the spaces with @@

If you can’t get it to work, there are other options including the 1.x version binding and the executeCommandLine action.

I tried this with no success:

Thing exec:command:echo_exec4 [command=“/bin/echo abcdef@@%2$s@@”, interval=10, autorun=true, timeout=5]

Is there a formal way to submit a bug? Or is posting it here good enough.

You submit an issue at the openhab2-addons repo on github.

Thanks for walking me through this Rich.
I have opened a bug here:


Take care

Yep, I’m having the same problem. And @namraccr seems to be on the right track - when you use a “run” channel type, it’s referencing lastInput, which is only assigned by the “input” channel type.

Problem is in “%” and till now not solved