I think the whitespaces in the command could still make some problems.
Let‘s start with a bullet proof test.
Create a .bat file e.g. in your scripts folder with this command
dir > c:\path to your script file\output.txt
and call this command through executecommand line.
Eventually you have to start command.com and pass the batch file as an argument
If that works then replace dir with google command.
I created a test.bat. If I start it manually it writes the output.txt.
Started with executecommandline it does nothing.
I dont know excatlly how to start it with command.com.
2023-08-24 21:59:00.869 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'Test-1' failed: An error occurred during the script execution: index=1, size=1 in Test
I used winthing (no serice) to restart OH and IOTlink (service) to start command on my other computers.
IOTLink has the same windows service restrictions as OH running as a service. Winthing and IOTLink are not supported any more. So after solving the service restriction problem I wanted to give the exec binding a try not knowing the problem it cuases on windows.
var response = executeCommandLine(Duration.ofSeconds(5),"C:\\test.bat")
logInfo("Test ON", response)
This does not:
var response
rule "Test ON"
when
Item Test changed from OFF to ON
then
response = executeCommandLine(Duration.ofSeconds(5),"C:\\test.bat")
logInfo("Test ON", response)
Syntax. You haven’t declared return as a variable. It needs to be
var response = ...
Ok. Now we have a starting point. test.bat is executed and output.txt is generated? Did you make sure it was not an old one from one of your tests from command line interface?
If you start chrome.exe from within your .bat file then we face the next problem that it is not loaded. Then you can try your solution by deactivating UAC
the command notepad.exe works on the command line.
But
var response = executeCommandLine(Duration.ofSeconds(60),"cmd.exe","/c","notepad.exe")
logInfo("Test ON", response)
leads to:
2023-08-25 11:14:55.160 [INFO ] [rg.openhab.core.model.script.Test ON] - Der Befehl "notepad.exe" ist entweder falsch geschrieben oder konnte nicht gefunden werden.