OpenHab 3.2.0.M4 - how to: executeCommandline

I’ve created a rule, and the script, after adding the shebang and +x permission the command is correctly executed.
Now I’m wondering how to add the results as loginfo.


var String results = ""

logInfo("Titolo","testo" + results)

echo "ciao" >> /tmp/ciao


==> /var/log/openhab/openhab.log <==

2021-12-13 10:22:28.701 [INFO ] [org.openhab.core.model.script.Titolo] - testo

2021-12-13 10:22:28.702 [DEBUG] [e.automation.internal.RuleEngineImpl] - The rule 'fde860b80a' is executed.

If I replace this row in rule, it goes to error:


[ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'fde860b80a' failed:   
var String results = ""
results=executeCommandLine("/home/op ___ enhabian/workspace/")
logInfo("Titolo","testo" + results)
   Type mismatch: cannot convert from void to String; line 4, column 36, length 57
var String results = ""

First, capture your results -

results = executeCommandLine("/home/...")

but that won’t wok because it doesn’t wait for the external script to run before assigning results. So allow some time -

results = executeCommandLine(Duration.ofSeconds(5), "/home/...")

It works like a charm, thank you!
Have a nice day

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.