openHab3: Failed to execute commandLine

Hi all,

today I upgraded from OH2.5 to OH3 and all went fine so far. Now I am testing all my different rules and commands. At one point I getting stucked on an error I cannot explain:

Failed to execute commandLine ‘[node /etc/openhab/scripts/node_modules/njstuya/njstuya.js]’

The command is whitelisted, the ownership is set to openhab und the rights on the file are 777

Has somebody an idea how to solve this ?


The syntax of executeCommandLine has changed. See here.


yes I know and my new syntax is as following:

execResult = executeCommandLine(Duration.ofSeconds(6), tuyaScript + configStr + triggeringItem.state)

results in

execResult = executeCommandLine(Duration.ofSeconds(6), “node /etc/openhab/scripts/node_modules/njstuya/njstuya.js”)


All arguments must be in separate strings:

execResult = executeCommandLine(Duration.ofSeconds(6), "node", "/etc/openhab/scripts/node_modules/njstuya/njstuya.js")

I don’t see what part comes from triggeringItem.state, so maybe the command must be:

execResult = executeCommandLine(Duration.ofSeconds(6), "node", "/etc/openhab/scripts/node_modules/njstuya/njstuya.js", triggeringItem.state)
1 Like

Thanks a lot there the issue was…


I have just filed

to get this properly documented.

Here is how it will look in the docs:
Actions | v3 Documentation Preview (deploy-preview-1369–

Feedback is highly appreciated.
cc to @holgerf who commented on my issue on github.


Sorry to interrupt: There is always this syntax used:
-> Duration.fromSeconds(timeout)
But for me it only works (DSL-Rule) with:

See also here:

1 Like

Good catch!
@Confectrician can you please correct this in the documentation?

1 Like


next problem:

  • How can i use the String output of executedCommandLine. It does not work at OpenHab 3.0:

In my DSL-Rule:
var String test = executeCommandLine(Duration.ofSeconds(5),"/etc/openhab/scripts/

if(test == “ON”){
}else if(test == “OFF”){ }

When i log the value of test, everything is alright but no if condition is working. It is like there was no if condition.
What confusingly works:

var String test = “ON”
if(test == “ON”){
}else if(test == “OFF”){ }

the if conditions are working now but what is different? The waiting time for a correct value is long enough.

Thank you in advance!

Perhaps the command has white space before or after the result.

"ON" != " ON"

Perhaps an invisible character like a CarriageReturn? Can you log the length of the test string?

Good idea but it is not the problem. The if conditions are simply skipped. Its offline, because my start condition is Offline. Both ifs are not active. When i uncomment: //test=“ON” the rules are working again.
Here is my script:

ping -c1 $1 > /dev/null

if [ $? -ne 0 ]; then
echo “OFF”
echo “ON”


21:51:25.541 [INFO ] [openhab.event.ItemCommandEvent ] - Item ‘Debug_Button’ received command ON
21:51:25.554 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item ‘Debug_Button’ changed from OFF to ON
21:51:25.837 [ERROR] [org.openhab.core.model.script.test ] - ON

21:51:25.841 [ERROR] [org.openhab.core.model.script.kamera1] - Kamera1_Status (Type=StringItem, State=Offline, Label=Kamera 1, Category=null, Groups=[gStatus])

my rule:

rule "Debug_Button"


Item Debug_Button changed

    var String test = executeCommandLine(Duration.ofSeconds(5),"/etc/openhab/scripts/", "")
    logError("test", test)

    if(test == "ON"){


            Kamera1_Status_lastseen.postUpdate( new DateTimeType() )

    }else if(test == "OFF"){

    logError("kamera1", Kamera1_Status.toString)

No, if conditions don’t just get skipped. Code doesn’t work like that. They are evaluating to false.

Notice how there is a stray newline between your log line of the value of test and the next one. That means the script is returning



not “ON”.

Newline is often represented with \n so maybe that will be more clear.

"ON" != "ON\n"

Change your log statement to

logError("test", "\""+test+"\"")

and you will see that your script is returning more than just “ON”.

1 Like

thank you very much! You were totally right. But why did it work on OpenHab2?

the log says:

22:03:38.145 [ERROR] [org.openhab.core.model.script.test ] - "ON
Why is there a gap?

executeCommandLine was rewritten in OH 3. Frankly, the current way it behaves is more correct. echo outputs the message followed by a newline. If OH 2 didn’t include the newline it wasn’t returning the full output of your script which is wrong.

1 Like

Thank you! I solved it.

For everybody else you need to add:

echo -n “xy”

I have added a comment to my pull request and will fix it.


While you are at it, the paths to the files in the Console page describing how to change the password are still openhab2. I’ve got a sticky note on my monitor but if you’re already making a PR…:wink:

Could you do me a favor and transfer the sticky note to a one liner issue in the repo?

I am on mobile currently.

It was just as easy to create the PR. :smiley: