I am running OpenHab on a Windows 10 machine. So everything is working and my rules are also working.
I’d like to create an item to restart the OpenHab service. I have already a working batch which can be used manually on the device.
I prepared everything and tried to run a simple batch file from a rule. I tried a command like this:
val String results = executeCommandLine("C:\\Temp\\test.bat", 100)
logInfo("TEST", "Skript" + results)
I can see that the rule is triggered but in the Log it only shows “Skript” without anything else. I tried to trigger a batch or an executable without success.
I don’t think the whitelist is (currently) used for exec Action anyway.
That’s normal enough in itself. Depends what the mystery batch does.
This is made difficult because the process that you want to restart openHAB will be running under openHAB.
Maybe it’s possible to use Windows Scheduler.
Already have the scheduler which is restarting every night. Last week I had an issue and my wife was not able to restart so I am searching for an easy way that she can do in future.
So no chance to run a batch which is tagged with the admin credentials?
Yes, I run batch under Windows from executeCommandLine just fine.
Simple test to demonstrate it works executeCommandLine("notepad.exe")
If that pops up a notepad, you’ll know your problems are something about your context.
My circumvention about scheduler was to schedule a one-time job in, say, one minutes time.
Works for me. No point in trying anything else until you get that to work.
Are you running openHAB as a service? I don’t know if that makes any difference.
Yes, OH is running as a service. How can I troubleshoot that because there is nothing in the log?! I can see that my rule is triggered but notepad won’t start.
Yes, but you will find a DOS command like del filename cannot be executed directly from executeCommandLine - because del is not a program, you are not typing into a dos box here. You would have to use cmd /c del filename
But as said, off topic.
notepad.exe is a program file and should run.
Something in your setup is preventing it opening a new window.
What timeout are you using in your test? 100mS is not long to fire up notepad.
sorry for the late response and thanks for your help. The echo test is working. But if I try to use “cmd /c notepad.exe” or cmd /c “full path to notepad.exe” then I just got the message, that this command can’t be found.
How can I solve to open an application? Any more hints?
The appropriate test is just
notepad.exe
It’s not a part of cmd.exe
The echo test works. So you know executeCommandLine() works.
You don’t yet seem to have verified if you are actually running your bat. Maybe add an echo to your bat before your suspect notepad line, and find out.
I still suspect you have some kind of permissions issue preventing a bat run from openhab user opening a new window. But you don’t seem to have thought about timeout either.