How do I remove EOF from pipes? Or: How do I use tail -f with netcat?

I am trying to connect XBoard chess commands over TCP. I understand that it nc

will close the connection when it sees EOF.

Example 1

$ nc -l 1301 | hd &
[1] 10241
$ echo -en "babab" | nc localhost 1301
00000000  62 61 62 61 62                                    |babab|
[1]+  Done                    nc -l 1301 | hd


This is my problem and I just think I need to figure out how to make it so that the command nc -l

above does not end. I read that I can use tail -f

, but it doesn't work unless I use files or FIFOs. Now, here is an explanation for a similar problem (I think) that made me find a solution to this problem:

Example 2

I want to run XBoard Chess engine in browser and exchange data via WebSockets. So I start XBoard like this:

./websockify 2023 -- xboard -fcp "nc -q -1 -k -l 2023"


It starts up and websockify seems to be forgetting the original commands from XBoard. Now I connect the browser like this:

ws = new WebSocket("ws://localhost:2023/", "base64");
ws.onclose = function(){console.log("close");};
ws.onmessage = function(evt){console.log(window.atob(;};
ws.onopen = function(){console.log("open");}


(executed in the console on one line)

It connects and I take the first step in the XBoard white, this is the output in the browser console:

protover 2
[2 second delay]
[other commands]
time 30000
otim 30000


Things are good. Now I make the movement black, from the browser: ws.send(window.btoa("move b7b5\n"));

Also works.

Now when I go and do the third game turn in XBoard, it no longer works. Right after mouseup, this console output appears:

  1: Target closed
xboard: Error writing to first chess program: Broken pipe
xboard: Error writing to first chess program: Broken pipe
xboard: Error writing to first chess program: Broken pipe
xboard: Error: first chess program (nc -q -1 -k -l 2023) exited unexpectedly


The graphical interface shows the same.

So my hypothesis is that EOF is somehow sent from XBoard to netcat after the first move. It doesn't really make sense because you don't think it was possible to disable the "target closed" report earlier? And what made the first step so different from all the other commands sent by XBoard?


source to share

1 answer

Yes! I found a solution.

I changed the command "engine" xboard to ./

and wrote

as (run flag set):

nc -q -1 -k -l 2023 | tee /dev/null


Everything works now!



All Articles