0

I’ll admit I don’t fully understand named pipes. I’ve read everything I can about them, but I’m still not sure how to keep one ‘open’ for repeated use. Basically, I want to use a named pipe as input to a program, and repeatedly send commands to that program.

In more detail: I am running a Minecraft Bedrock server inside an Ubuntu Docker container on macOS. I currently have Docker set up to start a detached tmux session running bedrock_server (the Minecraft binary), and I attach to the tmux session from the host OS to send commands and read output.

For the purposes of this question, the binary is just a program that takes input from stdin and sends output to stdout, but should only be executed once (it isn’t executed for each command on stdin).

To script the server, I have to use tmux send-keys, which is somewhat of a hack. I’d rather avoid tmux completely and run something like

./bedrock_server >> server.log < command.fifo

In fact, that’s exactly what I’m doing now. Logging works fine, but the issue is this: I can only send one line (using echo) to the program, and then the fifo closes (I think). Sending anything more causes no output on the logs. If I use the fifo as input to tail -f, the second message and any after do not get sent.

So, is it possible to keep the fifo ‘open’ to send multiple lines at different times? If not, is there another way to send data to a running process without putting the process in the foreground?

αғsнιη
  • 41,407
tjcaul
  • 101
  • Yes, thank you. I didn’t realize that EOF is sent when there are no writers. – tjcaul Jul 20 '21 at 04:47
  • An additional method is to have the reader process itself also be a writer. When it chooses to exit (maybe because some other writer sent it a 'STOP' message through the pipe, or some timer expired), it closes its write fd, and so gets an EOF on the pipe as soon as no other writers exist. – Paul_Pedant Jul 20 '21 at 15:21

0 Answers0