Отправка команд в консольное приложение?

Я хочу что-то проверить, потому что в моей голове это имеет смысл, но в Java это не работает.

Я пытаюсь запустить другой файл Jar через мое приложение. Сервер Minecraft, если быть точным. У меня есть все основы вниз (используяProcessBuilderвыполнение с аргументами, ожидание кода выхода и т. д.), но есть одна вещь, которую я не могу понять. Отправка команд в приложение. Здесь часть моегоCommandLineSender учебный класс:

public class CommandLineSender extends Thread {

    private BufferedWriter output;
    private InputStream source;  // Set to System.in when creating the object
    private boolean stopRequested;

    public CommandLineSender(Process sendTo, InputStream source) {
        this.output = new BufferedWriter(new OutputStreamWriter(sendTo.getOutputStream()));
        this.source = source;
        System.out.println("Source InputStream initiated: " + source.toString());
        this.stopRequested = false;
    }

    @Override
    public void run() {
        System.out.println("Run called.");
        Scanner cmdScanner = new Scanner(source);
        while (cmdScanner.hasNextLine() && !stopRequested) {
            System.out.println("Has next line");
            String msg = cmdScanner.nextLine();
            write(msg);
            System.out.println("Wrote: " + msg);
        }

        // Close the scanner and BufferedWriter

        System.out.println("Closed.");

    }

    // Other various methods

    protected void write(String msg) {
        try {
            output.write(msg);
        } catch (IOException e) {
            System.err.println("Unable to write message because of an unhandled IOException: " + e.getMessage());
        }

    }

Вывод, который я получаю это:

(Default Minecraft server output)

help  // My command
Has next line
Wrote: help

Это может не иметь значения, но я выполняю свой сервер с этими аргументами:

java -Xmx1024M -Xms1024M -jar (path to server jar) nogui

Спасибо за ваше время.

Ответы на вопрос(1)

Ваш ответ на вопрос