Exec binding not executing several commands within one openHAB-command


I want to execute three commands, one after another, for the ON and OFF openHAB-command.
Here is my items conf:

Rollershutter Shutter_EG_HST_F “HST_F” (Shutters_EG, Shutters_West, Shutters_West_Summer, Shutters_Nacht, Shutters_Tag) {exec=">[UP:/usr/local/bin/bus.py 32 18 4 1 1 && sleep 1 && /usr/local/bin/bus.py 32 18 4 0 1] >[DOWN:/usr/local/bin/bus.py 36 18 4 1 1 && sleep 1 && /usr/local/bin/bus.py 36 18 4 0 1]"}

In the logfile I can see that the commands are executetd, but actually they are not.

2016-07-22 11:47:27.012 [INFO ] [.o.b.exec.internal.ExecBinding] - executed commandLine ‘/usr/local/bin/bus.py 32 18 5 1 && sleep 1 && /usr/local/bin/bus.py 32 18 5 0’

Only the first one is executed, I don’t know about the sleep 1 but the 2nd bus.py is definitely not executed.
I read here about similar problems and also tried to replace the spaces in the command with @@, without success.

Does anybody know how to write the items exec string to work?

ps.: I know that I can rewrite my python code or wrap a shell script around it to do the sleep or handle the functionality in an OH script, but at the moment I’m only interested in the exec binding.


The only way to get the text that is printed when the commands execute is to use executeCommandLine with a timeout.

val String results = executeCommandLine("/usr/local/bin/bus.py 32 18 4 1 1 && sleep 1 && /usr/local/bin/bus.py 32 18 4 0 1", 5000)
logInfo("Exec", results)

This will tell you what, if any error is bing printed when this command executes. Once you get some feedback on what it is actually doing and figure out how to make it work you can move it back to the exec binding.

If I had to guess I’d say the problem is the “&&”. Keep in mind that “&&” is a shell command and it is not supported by all shells (some use “;”, some use “&”, some don’t support this concept at all). Furthermore, the openhab user is configured without a shell at all (i.e. its shell is /bin/false) so there is no shell for the openhab process to inherit when the Exec binding makes its calls. You may need to run /bin/bash -C first in order to use constructs like “&&”.

/bin/bash -C '/usr/local/bin/bus.py 32 18 4 1 1 && sleep 1 && /usr/local/bin/bus.py 32 18 4 0 1'

thanks for the hint with logInfo, I tried it but did not get any output returned.
So I decide to handle the execution and sleep in a rule:

  rule "Shutter_EG_HST_F"
        Item Shutter_EG_HST_F received command
        if (receivedCommand ==UP)
        {executeCommandLine("/usr/local/bin/bus.py 32 18 4 1") Thread::sleep(1000) executeCommandLine("/usr/local/bin/bus.py 32 18 4 0")}
        else if (receivedCommand ==DOWN)
        {executeCommandLine("/usr/local/bin/bus.py 36 18 4 1") Thread::sleep(1000) executeCommandLine("/usr/local/bin/bus.py 36 18 4 0")}

and removed the exec from the items.


Pay close attention to my example.

You must supply a timeout in the call to executeCommandLine as the second argument or else the call will immediately return without waiting for the command to execute. I used 5000 for five seconds in my example.

You must set the value returned by executeCommandLine to a val so it can be logged. I called it results in my example.

Finally you must log the returned value so what ever was printed by the called commands appear in openhab.log.

Change your calls to executeCommandLine to match my example above and you will see what your commands are printing.