Injecting text into bukkit console from java program

Discussion in 'Bukkit Help' started by Morlok8k, Apr 5, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    Morlok8k

    I'm reposting this in this forum where it will get more views...

    Hi,

    I'm coding a java program, MinecraftLandGenerator 1.3.0, where I spawn a minecraft server, read the text from it, and when it says "[INFO] Done" I send the text "stop" to it. MLG then moves the spawn point and runs the server again and again...

    This works just fine on the vanilla server, on practically every operating system.

    With Bukkit, I can read the output of the console. but when it comes to sending text back to bukkit, it fails.

    this is the current code that i have. but bukkit doesn't accept my OutputStream. (nothing happens) You can check out all my code on github here: https://github.com/Morlok8k/MinecraftLandGenerator

    any ideas?
    i think the fact that when bukkit normally runs it has a ">" on each line when it expects input is some how messing it up.


    Code:
    protected static void runMinecraft(ProcessBuilder minecraft, boolean verbose) throws IOException {
        System.out.println("Starting server.");
        Process process = minecraft.start();
    
        // monitor output and print to console where required.
        // STOP the server when it's done.
        BufferedReader pOut = new BufferedReader(new InputStreamReader(process.getInputStream()));
        String line;
        while ((line = pOut.readLine()) != null) {      //Read output of server console
            if (verbose) {
                System.out.println(line);               //Output if in verbose mode
            }
            if (line.contains("[INFO] Done")) {         //if done, we need to stop.
                System.out.println("Stopping server.");
                byte[] stop = {'s', 't', 'o', 'p', '\r', '\n'};
                OutputStream outputStream = process.getOutputStream();
                outputStream.write(stop);               //write "stop" to console
                outputStream.flush();
            }
        }
        // readLine() returns null when the process exits
    }
    
     
  2. Offline

    Morlok8k

    bump...
     
  3. Offline

    TnT

    Read over this thread - its about how the console interacts. You will find your solution in that thread.
     
  4. Offline

    Morlok8k

    Thanks, that was what I wanted to know.
     
Thread Status:
Not open for further replies.

Share This Page