I'm trying to send a command to a minecraft server jar using /proc/{pid}/fd/0 but the server does not execute the command.
To replicate what I'm trying to do you can do this on a Debian based machine (possibly other Linux distributuions aswell).
What I use to test this:
- Ubuntu 14.04
- minecraft_server.jar (testing with 1.8)
- OpenJDK Runtime Environment (installed with default-jre-headless)
First console:
$ java -jar minecraft_server.jar nogui
Response: [ ... server starts and waiting for input]
say hi
Response: [19:52:23] [Server thread/INFO]: [Server] hi
Second console:
Now when i switch to the second console, with the server still running in the first i write:
echo "say hi2" >> /proc/$(pidof java)/fd/0
Everything looks well until I switch back to the first console. I can see the text "say hi2" but the server hasn't recognized it. I can write another command in the first console again and it is as if the text inputted from the second console hasn't even existed.
Why is this? And more importantly, how do I use /proc/{pid}/fd/0 in a proper way to send commands to a java jar file?
I don't know if this is some kind of Java-thing that I'm not aware of, if I can use some flag or something when executing the server, or if it's the server jar itself that is the problem..
I'm aware that you can use screen, tail -f or some kind of server wrapper to accomplish this, but that's not what I'm after. I would like to send a command using this method, in some kind of way.