Execute Script via executeCommandLine in a rule is not working

Hey guys,

on my old openHAB 2.x installation I used executeCommandLine() in a rule and it worked without any problems.
For openHAB 3 I changed the path from /etc/openhab2/scripts/ to /etc/openhab/scripts/ :

rule "HarmonyHub - Apple TV, Netflix, Prime, Disney+ einschalten"
when
    Item WohnzimmerHarmonyHubCurrentActivity changed to "AppleTV" or
    Item WohnzimmerHarmonyHubCurrentActivity changed to "Netflix" or
    Item WohnzimmerHarmonyHubCurrentActivity changed to "Amazon Video" or 
    Item WohnzimmerHarmonyHubCurrentActivity changed to "Disney+"
then
    logInfo(filename, "Apple TV, Netflix, Amazon Prime oder Disney+ eingeschaltet")
 
    executeCommandLine("/usr/bin/python /etc/openhab/scripts/dreamscreen.py -m 1")
    
    Thread::sleep(500)
 
    executeCommandLine("/usr/bin/python /etc/openhab/scripts/dreamscreen.py -s 0")
end

And I got the following error message:

2021-01-02 20:26:12.107 [WARN ] [rg.openhab.core.io.net.exec.ExecUtil] - Error occurred when executing commandLine '[/usr/bin/python /etc/openhab/scripts/dreamscreen.py, -m 1]'
java.io.IOException: Cannot run program "/usr/bin/python /etc/openhab/scripts/dreamscreen.py": error=2, Datei oder Verzeichnis nicht gefunden
	at java.lang.ProcessBuilder.start(ProcessBuilder.java:1128) ~[?:?]
	at java.lang.ProcessBuilder.start(ProcessBuilder.java:1071) ~[?:?]
	at org.openhab.core.io.net.exec.ExecUtil.executeCommandLine(ExecUtil.java:59) [bundleFile:?]
	at org.openhab.core.model.script.actions.Exec.executeCommandLine(Exec.java:40) [bundleFile:?]
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]
	at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
	at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.invokeOperation(XbaseInterpreter.java:1176) [bundleFile:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.invokeOperation(XbaseInterpreter.java:1151) [bundleFile:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._invokeFeature(XbaseInterpreter.java:1137) [bundleFile:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.invokeFeature(XbaseInterpreter.java:1082) [bundleFile:?]
	at org.openhab.core.model.script.interpreter.ScriptInterpreter.invokeFeature(ScriptInterpreter.java:151) [bundleFile:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:992) [bundleFile:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:955) [bundleFile:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:236) [bundleFile:?]
	at org.openhab.core.model.script.interpreter.ScriptInterpreter.doEvaluate(ScriptInterpreter.java:226) [bundleFile:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:216) [bundleFile:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:459) [bundleFile:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:240) [bundleFile:?]
	at org.openhab.core.model.script.interpreter.ScriptInterpreter.doEvaluate(ScriptInterpreter.java:226) [bundleFile:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:216) [bundleFile:?]
	at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.evaluate(XbaseInterpreter.java:202) [bundleFile:?]
	at org.openhab.core.model.script.runtime.internal.engine.ScriptImpl.execute(ScriptImpl.java:80) [bundleFile:?]
	at org.openhab.core.model.script.runtime.internal.engine.DSLScriptEngine.eval(DSLScriptEngine.java:125) [bundleFile:?]
	at org.openhab.core.automation.module.script.internal.handler.ScriptActionHandler.lambda$0(ScriptActionHandler.java:62) [bundleFile:?]
	at java.util.Optional.ifPresent(Optional.java:183) [?:?]
	at org.openhab.core.automation.module.script.internal.handler.ScriptActionHandler.execute(ScriptActionHandler.java:59) [bundleFile:?]
	at org.openhab.core.automation.internal.RuleEngineImpl.executeActions(RuleEngineImpl.java:1179) [bundleFile:?]
	at org.openhab.core.automation.internal.RuleEngineImpl.runRule(RuleEngineImpl.java:987) [bundleFile:?]
	at org.openhab.core.automation.internal.TriggerHandlerCallbackImpl$TriggerData.run(TriggerHandlerCallbackImpl.java:89) [bundleFile:?]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) [?:?]
	at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
	at java.lang.Thread.run(Thread.java:834) [?:?]
Caused by: java.io.IOException: error=2, Datei oder Verzeichnis nicht gefunden
	at java.lang.ProcessImpl.forkAndExec(Native Method) ~[?:?]
	at java.lang.ProcessImpl.<init>(ProcessImpl.java:340) ~[?:?]
	at java.lang.ProcessImpl.start(ProcessImpl.java:271) ~[?:?]
	at java.lang.ProcessBuilder.start(ProcessBuilder.java:1107) ~[?:?]
	... 35 more

The file is available, I can run the command directly via the command line.

Thank you :slight_smile:

Dumb question, did you move the script to the changed folder as well? If not, the error observed would be telling!

Yes, it’s in the correct folder (I made a fresh install of openHAB, because I moved to another home).
Bildschirmfoto 2021-01-03 um 10.01.00

I can execute the script directly without any error:
Bildschirmfoto 2021-01-03 um 10.05.21

What does the script do/return?
When running it directly you are doing that as which user? openhabian? OpenHAB does it as user openhab!

I run the script as user sebastian, the scripts only returns an error.

It is the following script: DreamScreenCommander/DreamScreenComander.py at master · genesisfactor/DreamScreenCommander · GitHub

See also here because

The action executeCommandLine() has a new syntax and needs to be adapted in DSL rule files.

The commandLine must be split if it contains spaces.

2 Likes

Running a PHP scripting OH3 which has a return loks like:

var result=executeCommandLine(Duration.ofSeconds(12), "php","/etc/openhab/scripts/GetValues.php")

1 Like

Thank you so much @uk59821 and @opus :slight_smile:

Now it works!

executeCommandLine("/usr/bin/python", "/etc/openhab/scripts/dreamscreen.py", "-m", "1")

Please help
val result = executeCommandLine("/usr/bin/python /etc/openhab2/scripts/shaddow.py update", 10000)
error

If you are using OH3, you will need to use the new syntax as already described.

that’s from OH3 error
rule “Shaddow SVG”

when

Item Azimuth received update

then

    //val resp =  executeCommandLine("/usr/bin/python /etc/openhab2/scripts/shaddow.py update", 10000) old

    val result = executeCommandLine("/usr/bin/python /etc/openhab2/scripts/shaddow.py", 1000)

    logInfo("Shaddow", "Updating Shaddow SVG")          

    logInfo("Shaddow", result)          

end

Why don’t you read to posts in this thread. Some of them even use sentences, which make it possible to understand.

The rule calls when the sun is updated
an order. in Oh2 that was still possible.
therefore my question here

When you change from OH2 to OH3, you will need to change the syntax that you use with executeCommandLine()
The stuff in the brackets () needs to be laid out differently.
You’ve done well finding this thread, because it tells you what the new syntax is.
Now you need to read the other posts in this thread to find out what changes you need to make.
Start with the timeout parameter, as the easy part.

If you are having trouble, show us your best guess at the new syntax.

1 Like

You should use:

val result = executeCommandLine("/usr/bin/python", "/etc/openhab2/scripts/shaddow.py", 1000)

But have a look at the path /etc/openhab2/ - is this still correct?

so now goes the order
val result = executeCommandLine(Duration.ofSeconds(1000),"/usr/bin/python", “/etc/openhab2/scripts/shaddow.py”)
script is triggered again

Your original OH2 code was:

val result = executeCommandLine("/usr/bin/python /etc/openhab2/scripts/shaddow.py update", 10000)

And now the update argument is missing, without that the script doesn’t generate a new svg.
Also the timeout parameter was 10,000 milliseconds and now you use 1,000 seconds. That’s way to much.

I would try:

val result = executeCommandLine(Duration.ofSeconds(10), "/usr/bin/python", "/etc/openhab2/scripts/shaddow.py", "update")

The script is now running, only Influxdb does not receive any data. this is the next construction site.
Seconds(1)

So picture is updated now.
Command: val result = executeCommandLine (Duration.ofSeconds (10), “/ usr / bin / python”, “/etc/openhab2/scripts/shaddow.py”,'update ') ’ update ’