2

I'm running a server app (written in Java) under GNU/Linux which takes input (from stdin, I guess) and interprets it to run some commands. I dont want to run the app inside a terminal window (I'd like to run a daemon), but I'd still like to be able to input commands whenever I want to. I thought I might be able to do that using fifos, so I created it using mknod. The problem is cat fifofile > java... and cat fifofile | java ... fail with a "file not found" error for some reason.

Using only cat to read and write and the fifo works flawlessly.

Is there any way to fix this, or any other way to achieve the same goal?

kaoD
  • 1,534
  • 14
  • 25

2 Answers2

8

So, Minecraft? The best way to do this is to have a bona-fide tty for the console part of the application. screen is an easy way to do that.

Ben Jackson
  • 90,079
  • 9
  • 98
  • 150
  • Wow, didn't expect anyone to recognize Minecraft just from that description :) Thanks for the answer, I can't believe I didn't think about it! – kaoD Dec 30 '10 at 04:17
1

Have you tried java < fifofile? What about something like exec 3<&0; exec 0<fifofile; java?

What shell are you using? You might be able to use process substitution or coprocesses if you're using a shell that supports them.

Dennis Williamson
  • 346,391
  • 90
  • 374
  • 439
  • The problem with a named fifo in general is that the kernel matches up pairs of readers and writers. If he starts up `java < fifo` and later does `echo hello > fifo` then `java` will see "hello" followed by EOF. He'd need yet another persistent command to drive the input side of the fifo which puts him right back where he started. – Ben Jackson Dec 30 '10 at 03:44
  • Could _cat > fifo_ do the trick then? I'm gonna try, though I think this is getting more complex than it should. – kaoD Dec 30 '10 at 04:20
  • 1
    `cat > fifo` would work... *once*. So now your problem is what to do with the persistent `cat` instead of `java`. Plus the buffering through `cat` probably wouldn't be what you'd expect. – Ben Jackson Dec 30 '10 at 09:25