EXEC Binding not working with Windows 10 command

I’m running openhab on a windows 10 PC and I want to run a batch command file from habpanel. I’ve set the Thing and Items configs this way
Things:
Thing exec:command:pbalogo [ comand=“C:\PBAplay.bat %1”, interval=0 , autorun=true ]

Items:
Switch pbalogo {channel=“exec:command:pbalogo:run”}
String pbalogo_file {channel=“exec:command:pbalogo:input”}

The goal is to exec a batch file that will run a win media player with the filename being passed as a parameter .

Habpanel:
image
Im sending the file name for the video to run.

When I look at the log nothing is shown to be happening.
Any ideas on what’s not happening.

The Thing command has two slatches.
Thing exec:command:pbalogo [ comand=“C:\PBAplay.bat %1”, interval=0 , autorun=true ]

Shouldn’t that be command ?

1 Like

The little batch files that I use, I put into folder openhab\conf\scripts to simplify any access issues.

What @rdsgi means is that you should escape the backslash (and spell command)

Thing exec:command:pbalogo [ command="C:\\openhab\\conf\\scripts\\PBAplay.bat %1", interval=0 , autorun=true ]

Nothing in events.log for either Item? Then your command is not coming from Habpanel. Maybe you need some escapes there too. Look in events.log

This is what is in the event log:
2019-07-16 15:13:57.342 [ome.event.ItemCommandEvent] - Item ‘pbalogo_file’ received command “C:\DOCS\PBALogo.mp4”
2019-07-16 15:13:57.344 [nt.ItemStatePredictedEvent] - pbalogo_file predicted to become NULL

The command to the send file name to the pba_logo item is working but how does it start the send command item pbalogo

“C:\DOCS\PBALogo.mp4” is not a command. It is not executable , so it has no (NULL) output. IT appears OH is trying to execute the mp4 with the batch file as a parameter?
Just a newbie guess.

So what I want is to pass the file from the habpanel button and have that exec the item pbalogo with the parameter received by pbalogo_file item

That’s fine, Item ‘pbalogo_file’ is a String type and you can send it any string you like as a command.
The ‘prediction’ in the events.log comes from autoupdate, we can ignore that.

Okay, so we get a command string arrive at pbalogo_file. That is linked to the exec binding input channel. You have autorun=true set in the Thing, so the arrival of this command should trigger exec.

What should happen next is that exec will change the state of the Switch Item pbalogo, which is linked to the run channel, to ON, to say it is running. No sign of that in your events.log. So exec isn’t running.

Have you fixed that typo in your Thing yet?
Please post your Thing definition in code fences

It’s the opposite. You define the batch filename in the exec binding Thing, and may then send extra parameters like “banana” via the input channel. In this case, the parameter is a filename but exec don’t care.

Event log:
2019-07-17 15:54:19.457 [ome.event.ItemCommandEvent] - Item ‘pbalogo_file’ received command “C:\DOCS\PBALogo.mp4”
2019-07-17 15:54:19.466 [nt.ItemStatePredictedEvent] - pbalogo_file predicted to become NULL

after changes still no batch run
Thing:

Thing exec:command:pbalogo  [ comand="C:\\openhab2\\conf\\scripts\\PBAplay.bat %1", interval=0 , autorun=true ]
Items:
Switch pbalogo  {channel="exec:command:pbalogo:run"}
String pbalogo_file  {channel="exec:command:pbalogo:input"}

You’ve still got that typo. command has two ‘m’

Then, you’ll need to fix your parameter.
As per the exec binding docs, using %1 is about inserting current date and time.
If instead you want to use the input channel command as a parameter, then you must use %2. As you want it as a string, you’d use format $s
So, together %2$s

Thing exec:command:pbalogo  [ command="C:\\openhab2\\conf\\scripts\\PBAplay.bat %2$s", interval=0 , autorun=true ]

I suspect you might need to escape slashes in your parameter as well, but let’s get the script triggering first.

Fixed the typo, now its trying to process the command and shows this error on the openhab.log
2019-07-17 17:50:58.038 [ERROR] [hab.binding.exec.handler.ExecHandler] - An exception occurred while formatting the command line with the current time and input values : ‘Conversion = ‘1’’
Event log:
2019-07-17 17:50:58.022 [ome.event.ItemCommandEvent] - Item ‘pbalogo_file’ received command “C:\DOCS\PBALogo.mp4”
2019-07-17 17:50:58.032 [nt.ItemStatePredictedEvent] - pbalogo_file predicted to become “C:\DOCS\PBALogo.mp4”
2019-07-17 17:50:58.041 [vent.ItemStateChangedEvent] - pbalogo_file changed from NULL to “C:\DOCS\PBALogo.mp4”
2019-07-17 17:50:58.046 [vent.ItemStateChangedEvent] - pbalogo changed from NULL to ON
2019-07-17 17:50:58.048 [vent.ItemStateChangedEvent] - pbalogo changed from ON to OFF

in the example in the exec bind doc it shows the parm as %2$s in the Things, is this some form of formatting for the parm.

Yep, that’s what I said and its what the doc says, and gives you a link to formatting in detail.
You just want $s for string.

It’s probably failing on handling your string parameter because you need to escape those backslashes, I would try that first.

Change the parm to %s and added \ to file name

"C:\\DOCS\\PBALogo.mp4"

message in event log
2019-07-17 18:42:48.779 [ome.event.ItemCommandEvent] - Item ‘pbalogo_file’ received command “C:\DOCS\PBALogo.mp4”
2019-07-17 18:42:48.786 [nt.ItemStatePredictedEvent] - pbalogo_file predicted to become “C:\DOCS\PBALogo.mp4”
2019-07-17 18:42:48.789 [vent.ItemStateChangedEvent] - pbalogo_file changed from “C:\DOCS\PBALogo.mp4” to “C:\DOCS\PBALogo.mp4”
2019-07-17 18:42:48.790 [vent.ItemStateChangedEvent] - pbalogo changed from OFF to ON
2019-07-17 18:42:48.900 [vent.ItemStateChangedEvent] - pbalogo changed from ON to OFF

2019-07-17 18:42:48.779 [ome.event.ItemCommandEvent] - Item ‘pbalogo_file’ received command “C:\DOCS\PBALogo.mp4”
2019-07-17 18:42:48.786 [nt.ItemStatePredictedEvent] - pbalogo_file predicted to become “C:\DOCS\PBALogo.mp4”
2019-07-17 18:42:48.789 [vent.ItemStateChangedEvent] - pbalogo_file changed from “C:\DOCS\PBALogo.mp4” to “C:\DOCS\PBALogo.mp4”
2019-07-17 18:42:48.790 [vent.ItemStateChangedEvent] - pbalogo changed from OFF to ON
2019-07-17 18:42:48.900 [vent.ItemStateChangedEvent] - pbalogo changed from ON to OFF

2019-07-17 18:42:48.779 [ome.event.ItemCommandEvent] - Item 'pbalogo_file' received command "C:\\DOCS\\PBALogo.mp4"
2019-07-17 18:42:48.786 [nt.ItemStatePredictedEvent] - pbalogo_file predicted to become "C:\\DOCS\\PBALogo.mp4"
2019-07-17 18:42:48.789 [vent.ItemStateChangedEvent] - pbalogo_file changed from "C:\DOCS\PBALogo.mp4" to "C:\\DOCS\\PBALogo.mp4"
2019-07-17 18:42:48.790 [vent.ItemStateChangedEvent] - pbalogo changed from OFF to ON
2019-07-17 18:42:48.900 [vent.ItemStateChangedEvent] - pbalogo changed from ON to OFFyour code goes here

That all looks good.
No error in openhab.log this time?

You did mean to %2$s in the Thing?

Parm is set to %2$s
event log

2019-07-17 21:53:46.502 [ome.event.ItemCommandEvent] - Item 'pbalogo_file' received command "C:\\DOCS\\PBALogo.mp4"
2019-07-17 21:53:46.506 [nt.ItemStatePredictedEvent] - pbalogo_file predicted to become "C:\\DOCS\\PBALogo.mp4"

Final try - event log has…

2019-07-17 21:58:06.543 [ome.event.ItemCommandEvent] - Item 'pbalogo_file' received command "C:\\DOCS\\PBALogo.mp4"
2019-07-17 21:58:06.551 [nt.ItemStatePredictedEvent] - pbalogo_file predicted to become "C:\\DOCS\\PBALogo.mp4"
2019-07-17 21:58:06.557 [vent.ItemStateChangedEvent] - pbalogo_file changed from NULL to "C:\\DOCS\\PBALogo.mp4"
2019-07-17 21:58:06.559 [vent.ItemStateChangedEvent] - pbalogo changed from NULL to ON
2019-07-17 21:58:06.646 [vent.ItemStateChangedEvent] - pbalogo changed from ON to OFF

openhab log - no errors

Yes, that is exactly what we expect to see in events log.
The command comes in from your habpanel.
Exec binding turns pbalogo ON then OFF as it runs the script.
Job finished.

You don’t tell us, but is it not working still? With no clues in openhab.log I would guess everything on the exec binding side is working normally…
What does your batch script do if it gets a nonsense parameter? Does Windows give us permission to run it?

Sometimes you can gain more info by temporarily using the exec action in a rule - because you can get a result to look at

rule "testing batch"
when
   Item pbalogo_file received command
then
   var execresult = executeCommandLine( "C:\\openhab2\\conf\\scripts\\PBAplay.bat C:\\DOCS\\PBALogo.mp4",  3000)
   logInfo("test". "result: " + execresult
end