Solved How do I exactly write into the Bukkit process?

Discussion in 'Plugin Development' started by Cirno, Nov 15, 2014.

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

    Cirno

    I'm currently writing a wrapper for Bukkit so that it supports a rcon-like login system (i.e it contains user-password authentication, encrypted streams). However, when I attempt to write into the process (via Process.getOutputStream()) it does nothing. I've already tried tinkering with the server start up parameters by doing --nojline and the UnsupportedTerminal hack, but nothing's worked so far. I'm assuming the reason why is because ANSI skips System.in and goes directly to JNI/native methods or something, but I'm not quite sure.

    Anyone have a working method to writing to the Bukkit console thru Process.getOutputStream()?

    I realize this might be in the wrong section (this being a wrapper and the board subject is plugins) so if it is, you're free to shift this thread around. I posted it under PD because I felt that it might require a plugin add-in to act as the executor (i.e client -> wrapper -> plugin -> run command as console).
     
  2. Offline

    xTrollxDudex

    This seems like an interesting bit of information:
    Can you show relevant code?
     
  3. Offline

    Cirno

    Code:java
    1. try{
    2. socket.receive(recv);
    3. Logger.getLogger("debug").info("Got packet");
    4. String command = new String(recv.getData(), Wrapper.UTF8).substring(0, recv.getLength());
    5. Logger.getLogger("debug").info("Running command " + command);
    6. outputStream.println(command + '\n');
    7. } catch (IOException e){
    8. e.printStackTrace();
    9. }


    Where outputStream is Process.getOutputStream(). It does not throw an IOException because I never see any stacktrace.

    Ignore the silly getLogger() calls; I couldn't do System.out since I replace it with my own and it strangely causes a StackOverflow.
     
  4. Offline

    xTrollxDudex

    How did you even get the process anyways?
     
  5. Offline

    Cirno

    Code:java
    1. ProcessBuilder builder = new ProcessBuilder(serverArguments);
    2. builder.redirectInput(ProcessBuilder.Redirect.INHERIT);
    3.  
    4. try{
    5. Process process = builder.start();


    Where server arguments contains:
    Code:java
    1. serverArguments.addAll(0, Arrays.asList("java", "-jar"));
    2. serverArguments.addAll(serverArguments.size(), Arrays.asList(serverJar.getAbsolutePath(), "--nojline"));


    Remember, it's a wrapper, not an external application lol
     
  6. Offline

    xTrollxDudex

    Cirno
    Try redirecting the output
     
  7. Offline

    Cirno

    What do you mean by redirecting the output?
    I probably worded the post funny; I want to basically write into the subprocesses System.in so that I don't need to write a plugin to carry the command over to getConsoleSender(). However, when testing it, it doesn't work flat out; no errors, no exceptions, nothing.

    derp this part made no sense; reword later
     
  8. Offline

    xTrollxDudex

    Use inheritIO() in ProcessBuilder, it should redirect both the input/output steams to the current one.
     
  9. Offline

    Cirno

    You know what?
    I'm an idiot. A complete damned idiot. It was because I was making the subprocess inherit the wrapper's input, and thus, there technically was no output because I would need to write into my own processes System.in somehow...

    That statement was also probably confusing.
    tl;dr I called the wrong thing at the wrong time, and it caused this mess.

    Solved. Thanks for helping (cause if you didn't mention the whole inheritIO() thing, I would've never noticed it lol)
     
  10. Offline

    xTrollxDudex

    Glad I could help.
     
Thread Status:
Not open for further replies.

Share This Page