Exec persistence issues - piping to netcat

I’m trying to get sensor data into Graphite, by piping the values to netcat. As a simplified example of the issue, I have the following in my exec.persist which should send the text “pwd” to my docker host:

IndoorTemp -> “echo “pwd” | nc docker 8763” : strategy = everyMinute

The pipe into netcat doesn’t seem to function. Relevant log items:

03:19:00.103 [DEBUG] [.o.p.exec.internal.ExecService:51 ] - Executing command [echo “pwd” | nc docker 8763]
03:19:00.106 [DEBUG] [.o.p.exec.internal.ExecService:67 ] - Output from exec command is: “pwd” | nc docker 8763

Running the exact command referenced in the first log item works fine from the shell. Any ideas here?

My general suggestion is for all things exec to not use the exec binding or persistence until you get it working from executeCommandLine in a rule. So do the following:

  • create a switch you can use to trigger a rule to test your command
  • create a rule that triggers on that switch and put the following code in it:
val String results = executeCommandLine("echo \"pwd\" | nc docker 8763", 5000)
logInfo("ExecTest", results)
  • watch your openhab.log file for the results.

I’m willing to bet you will see an error being returned from your command that isn’t otherwise being captured by the ExecServices log. In my experience on this forum and personally, ALL exec problems are permission problems and this is the easiest way to see them.

Thanks for the tips. Here is the output:

18:58:59.239 [DEBUG] [m.r.internal.engine.RuleEngine:305 ] - Executing rule 'test cmd’
18:58:59.524 [WARN ] [g.openhab.io.net.exec.ExecUtil:141 ] - Process exited with an error: 0 (Exit value: 0)
18:58:59.526 [INFO ] [.openhab.model.script.ExecTest:53 ] - pwd | nc docker 8763

The results of the command (line 3 above) seems wrong. Instead of “pwd” being echoed into the pipe, it seems like the whole statement is being echoed.

Don’t you need to use backticks ` to cause echo to execute pwd instead of double quotes " ?

I confused thing by using pwd, but I’m just trying to sent a random string and not the output of the pwd command.

Doing research on executeCommandLine(), I think the problem could be similar that discussed here:

And here is a possibly relevant note from the source code on the use of the @@ delimeter:

* Executes commandLine. Sometimes (especially observed on
* MacOS) the commandLine isn’t executed properly. In that cases another
* exec-method is to be used. To accomplish this please use the special
* delimiter ‘@@’. If commandLine contains this
* delimiter it is split into a String[] array and the special exec-method
* is used.


* A possible {@link IOException} gets logged but no further processing is
* done.

Not sure how to implement this though…

You just replace the spaces with “@@”.


I don’t know if that applies to executeCommandLine though. Remember executeCommandLine and the Exec Binding are not te same thing.