How to use the exec binding with Windows 10

In command

I would expect to see commas between the arguments.

So if you solved it for the exec binding why don’t you use it ?

Yes. My fault. Maybe also replacing „/c“ with „\/c“

Would that be the right syntax?

logInfo(executeCommandLine(Duration.ofSeconds(5),"command.com","/c","start","\"\"","C:\\test.bat"))

I am not familiar anymore with DOS commands.

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.

Why is this not running?

not sure if the syntax is correct for logging, so better split it. I am not familiar anymore with DSL

var return = executeCommandLine …
logInfo ("test", return)

Please always provide any kind of results, logs etc otherwise we cannot help

OK this works:

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)

Is this logic or syntax …?

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

UAC is off.

    var response = executeCommandLine(Duration.ofSeconds(5),"echo Hallo")
    logInfo("Test ON", response)

leads to:

2023-08-25 09:52:30.314 [WARN ] [rg.openhab.core.io.net.exec.ExecUtil] - Failed to execute commandLine '[echo Hallo]'
2023-08-25 09:55:48.989 [INFO ] [rg.openhab.core.model.script.Test ON] - null

echo Hallo > c:\output.txt in the test.bat file works.

put “echo hallo” into your test.bat.
or try

var response = executeCommandLine(Duration.ofSeconds(5),"echo", "Hallo")

If this does not work you need to work with command.com as echo is an internal command

echo “Hallo” > c:\output.txt in the test.bat file works if started from openHAB.

var response = executeCommandLine(Duration.ofSeconds(5),"echo", "Hallo")

leads to:

2023-08-25 10:21:38.604 [WARN ] [rg.openhab.core.io.net.exec.ExecUtil] - Failed to execute commandLine '[echo, Hallo]'

what is the return value?
I gues you need to call echo command like this:

executeCommandLine(Duration.ofSeconds(2),"cmd.exe","/c","echo","hallo")

My fault. In all cases please replace command.com with cmd.exe.

1 Like

This works! returns hallo

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.

and what happens if you add notepad.exe to your batch file?
Please also provide for testing the whole path to notepad.exe

I don’t want to start Chrome or other programs from openhab. Its just a test. At least chrome should start.
I thought the executeCommandLine and the exe binding send the command to cmd.exe. But exept echo in a special format none of them work.

If I add notepad.exe to the bat file its not found. Adding it with the path C:\Windows\notepad.exe leads to
2023-08-25 12:08:42.986 [WARN ] [rg.openhab.core.io.net.exec.ExecUtil] - Timeout occurred when executing commandLine ‘[C:\test.bat]’

there was somewhere made the solution to deactivate UAC. Did you try that?

I found the solution to deactivate UAC and it is deactivtes on my PC.

When ? After the timeout that you set occurred or before ?
Question is here where will notepad be shown ? It runs in the background but you own the display.
What you could do is to check if notepad is started by using the taskmanager.
It may be started but ended after the timeout that you set. In case it starts in the background and is not closed again within the timeout it will be killed and you get the message that a timeout occurred.

So if you can find it running by using taskmanager you can see if it was started.