I don't think this is possible in
screen. You can use a fifo to get the output of a command in screen, but I doubt that the 'minecraft shell' will support that.
However this is 'doable' with
Process Status/Stack Trace
To make it work properly, you'd have to detect at which point the program you are feeding commands is stuck at a relevant IO Operation. A way to do that would be running a stack trace and looking for that. Also see: How do I tell if a command is running or waiting for user input?.
That may be a bit tricky because it may be temporarily stuck at at another
read before the desired one. It may also have to involve some guessing based on how long it is stuck and at which file descriptor. It could be combined with the line-counting proposal below for more accuracy.
While testing this, I encountered
select(1, , NULL, NULL, NULL (
python3 cli interpreter). There may be few other possibilities, which is why I didn't limit the
RegEx in the script below to just that. It is just looking for an open parenthesis now.
Maybe someone knows a more precise way to do this?
A good indicator might be to check if the process is running or sleeping. You can do this with
ps. This method is used in the proof-of-concept script below, in combination with the stack trace.
Having the Server running as a
Child Process in Node enables you to interact with the
stdout of the process in Node. You could just look for newlines (
\n) and if you know how many lines the output should have, you can count them and 'know' that it has finished running and is waiting for input again. You could combine it with a timeout.
Proof of Concept with Process Status/Strace
I moved the script and some docmentation to a github repository. I haven't tested this with mc, but it worked with
zsh (As far I could test it, see section "Tests"). It's still not perfect as it still involves some waiting and may or may not get false positives.
How to use
You can start the server/
tmux session like that:
tmux new-session -d -s server_name "java -jar minecraft_server.jar"
Sending a command to the server would look like that:
./trun.sh -s server_name -c "the command"
It should return the output of the server. You may have to adjust the
Beware that if you run this on a webserver, you can run into problems, especially if there are multiple users. You might have to implement a Lock to prevent multiple users accessing the shell at the same time. I'm sure that
tmux itself wouldn't have a problem with that, but you can't really predict the ouput if another command may have been run while you try to read said output.
If you intend to run this on a server exposed to the www, consider securing it (for example by using a password protected proxy via