Is there a reason OH 3 (Windows 10 3.1.0M1) executeCommandLine in a script will not run a batch file? Doesn’t matter where the file is. It will not run any batch file anywhere. I can run anything else just fine, but not a batch file. It immediately returns null.
Other things like dir also don’t work. But for example ipconfig works fine.
Anything that doesn’t work from the script works perfectly fine from the command line.
what does that exaclty mean ? Did you also put the batch file into a path that is known to the system like where the ipconfig command is located in ?
You may need to escape \ in paths like
c:\ => c:\\
Do you use arguments for your batch file ? How does your executeCommandLine look like ?
Is there any error mesage in openhab.log file ?
Does it help to start the batch file in a separate ‘shell’ ? executeCommandLine( "cmd","/c","c:\\path\\to\\your\batchfile")
you may need to add time to wait for the command to finish
For commands that don’t work, there is no error. It just instantly returns null and does nothing.
Using the full path to the file: var response = exec.executeCommandLine(Duration.ofSeconds(10),"c:\\openhab\\conf\\html\\camDayNight\\camDay.bat");
Not using the full path to the file, since that full directory is in the windows path environmental variable. exec.executeCommandLine(Duration.ofSeconds(10),"camDay.bat");
Forcing another shell I also already tried. exec.executeCommandLine(Duration.ofSeconds(10),"cmd.exe", "/c", "c:\\openhab\\conf\\html\\camDayNight\\camDay.bat");
Any of the above methods work with some commands and not with others. Like for example, exec.executeCommandLine(Duration.ofSeconds(10),"ipconfig"); works perfectly. But exec.executeCommandLine(Duration.ofSeconds(10),"dir"); does not.
I even tried putting the batch files in the windows/system32 directory to see if that would make it happy and it does not.
@rossko57 : what do you mean exactly by “are you running openHAB as a service? this seems to make a difference here”
Indeed, on my side, I’m struggling to find my issue, since executeCommandLine works fine in my rules if I start OpenHAB 3.1.0-M1 with .bat file, but not when I start it as a service: see here
Does it means I have to write it differently when OH3 is started as a service?
Here is the call in my rules so far: val resp = executeCommandLine(Duration.ofSeconds(10), "C:/Users/SEBASTIEN/AppData/Local/Microsoft/WindowsApps/python.exe", "c:/OpenHAB3/conf/scripts/shaddow.py", "update")
Thanks for your quick reply & the 2 links, I will continue to investigate.
What I don’t really get is that it was working perfectly with no difference when using OH 2.5, and no longer with OH3.
One big difference is the java version (8 for OH2.5, while 11 for OH3), and considering it’s the same Win 10 on my side (no new Win installation, no change except last 1909 big update on WIN10), I would rather think it’s related to JAVA or the wrapper config and not windows permission itself.
for the exec binding compared to executeCommandLine on top you need to make sure that the executable is on the whitelist.
that is correct. In the other example python is mentioned; it is possible to create/use UI with python but at a starting point I would not expect that the other user programmed a UI in his python script.