executeCommandLine on a Windows machine

``Hi Alain,
Thanks very much for the help. Unfortunately, I still can’t get it to work!!
I copied your rule and pasted into my rules file. I created a directory at C:\OH_utils and put head.exe and esai.txt into this directory.
I must have checked my directories and entries at least 10 times. When I run the program, the log file doesn’t report any error but here is the logging output:

2018-01-17 14:09:20.324 [INFO ] [eclipse.smarthome.model.script.DEBUG] - From essai.txt : 

I did create a rule with

	executeCommandLine("notepad.exe")

and it pops up a notepad exactly as expected

I am going to leave this alone for a while since I do have my workaround. When openhab works it’s really a wonderful program. But when I find myself banging my head against something that should be straightforward (which I often do) I have to go off and calm down. :grin:

Once again, thanks for the help.
Regards,
Joe

Seriously?! WHERE IS THE .TXT FILE?!

Use the full path to your txt file like @renstat did. Let us know.

Serious as a heart attack.
Here is my rule.

//Working rule copied from the forum advice
rule "Un test"
when
    System started
then
    val input = executeCommandLine("C:\\OH_utils\\head@@-n@@1@@C:\\OH_utils\\essai.txt", 1000)
    logInfo("DEBUG", "From essai.txt : " + input)
    if (input.contains("first")) logInfo("DEBUG", "the line contains <first> !")
end

As I stated in my previous post, I copied and pasted the rule from above , created a directory C:\OH_utils\ and in that directory I put head.exe and essai.txt . essai.txt contains a single line:

This is the first line in my file

I will not be surprised if the problem in hindsight turns out to be something simple and obvious. But I sure can’t see it.
Regards,
Joe

Hi Joe,

Perhaps an explanation !

After some research, I realized that there are several versions of head.exe for Windows hanging around on the web.
Some, as this one : http://unxutils.sourceforge.net/, are self-contained (no emulation layer) and have no dependencies.
Other, as this one http://gnuwin32.sourceforge.net/packages/coreutils.htm, are built on Cygwin or Mingw and require some DLL (such as iconv-x, intl-x, depending on versions). If you run the second category on the command line you get a Windows error box reclaiming these DLL (if they are not already in the same directory).

And when you run OpenHAB-executeCommandLine with the second category, it remains silent but you get no result !

The test of my first message was made with a utility of the first category which was sitting on my PC. I tried with one of the second category and had the same result as you !

I suspect you used one of the second category and as you copied head.exe “into the top level of your OS partition”, or in OH_utils, you lost the DLLs on the way.

Have a try with head.exe from http://unxutils.sourceforge.net/ and I am pretty sure it will be a success !

Regards,

Alain

2 Likes

Hi Alain,
blessings upon your head.

2018-01-19 18:33:40.772 [INFO ] [eclipse.smarthome.model.script.DEBUG] - From essai.txt : This is the first line in my file
2018-01-19 18:33:40.774 [INFO ] [eclipse.smarthome.model.script.DEBUG] - the line contains <first> !

Regards,
Joe

Does notepad actually pop up with a form? I see executeCommandLine started the notepad process, but it is not visible on the screen… I wonder if have OH configured to start with the wrong user?