I've made a small command to send a TCP message to an "IP-relay-unit" that can toggle the outputs.
printf "setstate,1:1,1\r" | nc ip.ip.ip.ip port
This actually works fine, sometimes. Since the printf worked on both linux and mac, I thought it had to do something with netcat. I noted that using -v on netcat improved the amount of times it went right, but this seems like a very dull workaround.
I later found the nc -i option, to add a timeout of 1 sec, which hasn't yet caused an error (on both Linux or OSX), though it does decrease the execution time and still isn't a 100% clean fix.
The man page actually shows that piping into the nc command can be done, it doesn't mention any possible race conditions.
Is this expected behaviour? And is there a clean way of fixing this? (like "--only-send-when-connection-is-complete") or can I actually check if it's a race condition?