2

I have a Minecraft server attached to a Screen in my linux server. I use Python to push data to the Minecraft server via Screen Stuff. I have noticed that if I put too many characters in screen stuff, it tends to not push the data into the screen.

For example, the following works just fine. It pushes the text to the Minecraft screen: screen -r Minecraft -p0 -X stuff 'Some random text etc etc, contents are not relevant ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------^M'

Adding 100 or so more characters causes the contents to not be sent and no error messages are produced that I can tell: screen -r Minecraft -p0 -X stuff 'Some random text etc etc, contents are not relevant-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------^M'

This seems to suggest there is a character limit within screen's stuff command. Assuming so, is there an alternative for this that would allow for more characters? I occasionally have extremely long commands to push to the screen that go above the 700-800ish character limit I am observing. Perhaps putting the text into a file and passing that along for the screen to run somehow?

2
  • Probably the stuff length is limited by the terminal driver buffer. - If you have a solution or a workaround, you should post it as an answer. Commented Mar 28, 2021 at 8:16
  • Doesn't Minecraft provide any way to connect to an existing to send commands? On the face of it, that would seem to make more sense than having to do tricks with screen. Commented Mar 29, 2021 at 17:12

2 Answers 2

3

Well, the man page does say stuff can't be used for large inputs:

stuff [string]

Stuff the string string in the input buffer of the current window. This is like the "paste" command but with much less overhead. [...] You cannot paste large buffers with the "stuff" command. It is most useful for key bindings.

But it does hint at paste:

paste [registers [dest_reg]]

Write the (concatenated) contents of the specified registers to the stdin queue of the current window. The register '.' is treated as the paste buffer.

readbuf [-e encoding] [filename]

Reads the contents of the specified file into the paste buffer. [...]

I tried it by pasting the screen man page (2600 lines, 166 kB) to an editor:

screen -S test -X readbuf /tmp/screen.txt
screen -S test -X paste .

and got the identical file back after saving it, so it seems paste might work better. This does have the downside of requiring more than one command, though, and I don't know if it can be done without passing the data through a file.

In any case, I'm not sure if pasting data through screen is the best way to send commands to a running server, but I don't know if Minecraft provides other ways to send commands than stdin.

One solution which I've seen done with another game server is to redirect input to the server from a pipe, like

tail -f inputfile | ./whateverserver ...

and then, if you need to issue commands to it, run echo some command >> inputfile. This should work similarly to stuffing input with screen.

Note that any solution like this that stuffs commands automatically to a single input has the problem that unless you're careful, multiple commands being sent at the same time may get mixed up. Really, this would need locking.

0

I found a workaround. Simply sending the command in parts that are under the character limit seems to work. Here is my setup in Python:

def runServerCode(code):
    while len(code) > 600:
        os.system("screen -r Minecraft -p0 -X stuff '" + code[:600] + "'")
        code = code[600:]
    code += "^M"
    os.system("screen -r Minecraft -p0 -X stuff '" + code + "'")

The only issue I have had with this is that occasionally other information will be sent to the screen before this code can complete causing the pushed code to be split somewhere in the middle, causing it not to run properly.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.