I’m running openHAB 2.5.5 as service on Windows 10.
I have a simple rule:
rule "Shutdown Server"
when
Item System_Shutdown received command ON
then
executeCommandLine("C:\\openHAB2\\conf\\bat\\shutdown.bat", 1000)
end
And the content of my shutdown.bat file is also pretty simple (for test purposes):
notepad.exe
I’ve been trying to make the EXEC binding work for quite a while and that what I’ve found:
if i start OH with the start.bat script, everything works and notepad window appears.
if i start OH as service, nothing happens and the log looks like this:
14:40:04.225 [INFO ] [smarthome.event.ItemCommandEvent ] - Item 'System_Shutdown' received command ON
14:40:04.240 [DEBUG] [clipse.smarthome.io.net.exec.ExecUtil] - executed commandLine 'C:\openHAB2\conf\bat\shutdown.bat'
14:40:04.303 [DEBUG] [clipse.smarthome.io.net.exec.ExecUtil] - exit code '1', result '
C:\openHAB2\userdata>notepad.exe
"notepad.exe" is not recognized as an internal or external command, operable program or batch file.'
So i’ve tried to start service not with SYSTEM, but my USER account, but the behavior stays the same.
I’ve also tried to add runas command to my batch file, but i get the same behavior.
So my question is how to make OH execute batch files when running as service?
I know this might not be an OH problem, but still maybe somebody knows what to try. I’ll appreciate any help.
Have you tried to use the full path to the exe file in the batch file ?
Alternatively you may check if the PATH variable includes the path where the executable is located.
But I am not sure - you may try it - if a program that requires a display can be executed.
Yes, I’ve tried using the full path. Also checked the PATH variable, the path to notepad.exe is listed there.
The batch file is executed successfully when running OH not as service.
Good point, thanks!
i’ve tried some non UI commands, and get the same error:
18:21:51.259 [DEBUG] [clipse.smarthome.io.net.exec.ExecUtil] - executed commandLine 'C:\openHAB2\conf\bat\shutdown.bat'
18:21:51.319 [DEBUG] [clipse.smarthome.io.net.exec.ExecUtil] - exit code '1', result '
C:\openHAB2\userdata>ipconfig /all
"ipconfig" is not recognized as an internal or external command, operable program or batch file.'
18:23:45.037 [DEBUG] [clipse.smarthome.io.net.exec.ExecUtil] - executed commandLine 'C:\openHAB2\conf\bat\shutdown.bat'
18:23:45.100 [DEBUG] [clipse.smarthome.io.net.exec.ExecUtil] - exit code '1', result '
C:\openHAB2\userdata>shutdown /r
"shutdown" is not recognized as an internal or external command, operable program or batch file.'
Want to bring this topic up again, because I have an issue running a command from OH3 under Windows 10 (OH3 runs as a Service). The rule I have should turn on the monitor in the morning from standby, when a motion detector becomes active. Here is the command I want to use for this:
var result = executeCommandLine(Duration.ofSeconds(10), "C:\\Tools\\NirCmd\\nircmdc.exe", "monitor", "on")
logInfo("GoodMorning", "EXE monitor on - {}", result)
The result in the log file is simply this (nothing):
2021-09-01 16:26:18.126 [INFO ] [penhab.core.model.script.GoodMorning] - EXE monitor on -
I tried any combination of “/” and “\” in the path, also added commands in the exec.whitelist, but it does not work.
I am running openHab 3.4 on Windows 11 (as a service)
I am trying to restart a binding from the gui by using the exec binding.
The command I use works perfectly fine when I open a command prompt, but not when I use the exec binding. The error I get is:
Passing to shell for parsing command.
OS: WINDOWS (Windows 10)
Exec [ERROR]: ‘The filename, directory name, or volume label syntax is incorrect.’
Use double backslashes instead of single backslashes.
I also would put bundle:restart and org.openhab.binding.mqtt.espmilighthub into their separate pair of double quotes delimited by comma.
Thanks for your fast response. The double backslash did the trick, although I don’t understand what it does. Putting the separate pair of quotes around bundle:restart and org.openhab.binding.mqtt.espmilighthub doesn’t seem be be necessary.
Windows uses single backslashes as separator un paths. Other OSs and software uses forward slashes. Backslashes are used to escaoe a subset of characters. This is why two of them are required.