OH 3 issue? String compare issue with OH 3?

Hello,

I have an issue with a string query with OH 3 RC1.

Short
if (OKExecute==“OK”) query is entered with OH 2.5 (this is what I want)
but NOT entered with OH 3.
Please tell what I’m doing wrong - THX.
Please have a look at the details

Details
OH 2.5.10

pi@raspberrypi:~ $ java -version
openjdk version “1.8.0_152”
OpenJDK Runtime Environment (Zulu Embedded 8.25.0.76-linux-aarch32hf) (build 1.8.0_152-b76)
OpenJDK Client VM (Zulu Embedded 8.25.0.76-linux-aarch32hf) (build 25.152-b76, mixed mode, Evaluation)

rule “Test1”
when
Item TestSwitch1 changed to ON
then

logInfo("Log","test rule start" )	

var String OKExecute=executeCommandLine("/opt/openhab2/conf/scripts/lock122.sh", 100)

logInfo("Log","OKExecute Value 1 " + OKExecute)		

if (OKExecute=="OK")
	{
	logInfo("Log","OKExecute Value 2 " + OKExecute)		
	}

logInfo("Log","test rule end" )	  

sendCommand(TestSwitch1, OFF)

end

pi@raspberrypi:~ $ cat /opt/openhab2/conf/scripts/lock122.sh
mkdir /tmp/lock122 && [ -d “/tmp/lock122” ] && echo “OK”

tail openhab.log
2020-12-19 10:20:11.987 [INFO ] [g.eclipse.smarthome.model.script.Log] - test rule start
2020-12-19 10:20:12.050 [INFO ] [g.eclipse.smarthome.model.script.Log] - OKExecute Value 1 OK
2020-12-19 10:20:12.054 [INFO ] [g.eclipse.smarthome.model.script.Log] - OKExecute Value 2 OK //the if query WAS entered
2020-12-19 10:20:12.057 [INFO ] [g.eclipse.smarthome.model.script.Log] - test rule end

OH 3.0.0.RC1 - Milestone Build

pi@raspberrypi:~ $ java -version
openjdk version “11.0.9.1” 2020-11-06 LTS
OpenJDK Runtime Environment Zulu11.43+100-CA (build 11.0.9.1+1-LTS)
OpenJDK Client VM Zulu11.43+100-CA (build 11.0.9.1+1-LTS, mixed mode)

rule “Test1”
when
Item TestSwitch1 changed to ON
then

logInfo("Log","test rule start" )		
var String OKExecute = executeCommandLine(Duration.ofSeconds(1),"/opt/openhab/conf/scripts/lock122.sh")

logInfo("Log","OKExecute Value 1 " + OKExecute)		

if (OKExecute=="OK")
	{
	logInfo("Log","OKExecute Value 2 " + OKExecute)		
	}

logInfo("Log","test rule end" )	  

sendCommand(TestSwitch1, OFF)

end

pi@raspberrypi:~ $ cat /opt/openhab/conf/scripts/lock122.sh
mkdir /tmp/lock122 && [ -d “/tmp/lock122” ] && echo “OK”

tail openhab.log
2020-12-19 10:32:01.700 [INFO ] [org.openhab.core.model.script.Log ] - test rule start
2020-12-19 10:32:01.735 [INFO ] [org.openhab.core.model.script.Log ] - OKExecute Value 1 OK //the if query WAS NOT entered
2020-12-19 10:32:01.743 [INFO ] [org.openhab.core.model.script.Log ] - test rule end

Many THX for your help

Klaus

Hi Klaus,

I have a similar problem here.
A rule that worked in OH 2.5 doesn’t do it now - at least comparing a variable created by executeCommandline with a string doesn’t work anymore. When I output the variable in the log, the expected string can be seen, then in the If(var==“string”){…} it obviously doesn’t work anymore.

Have you found a solution?

make sure that the output of your shell script does not contain any return value.
Instead of using

echo OK

you need to use

echo -n OK

Did a trial with lock122.sh containing:

#!/bin/sh
echo -n OK

and the output of the DSL rule contained in openhab.log file is:

2021-11-24 07:36:00.307 [INFO ] [org.openhab.core.model.script.Log   ] - test rule start
2021-11-24 07:36:00.324 [INFO ] [org.openhab.core.model.script.Log   ] - OKExecute Value 1 OK
2021-11-24 07:36:00.328 [INFO ] [org.openhab.core.model.script.Log   ] - OKExecute Value 2 OK
2021-11-24 07:36:00.329 [INFO ] [org.openhab.core.model.script.Log   ] - test rule end