I have a class that extends OutputStream and is used to make the output of said OutputStream into a Text or StyledText. The class works great, however it introduces a problem.
I am working on an SWT application that includes a fake console. I'm not using it to run sytem commands, but rather a few different Minecraft servers that I use for slightly different development environments/purposes.
From what I've read about ProcessBuilder, inheritIO() is supposed to make the resulting Process' IO streams the same as the Java process that created it:
From the Oracle Docs:
public ProcessBuilder inheritIO() Sets the source and destination for subprocess standard I/O to be the same as those of the current Java process.
This is a convenience method. An invocation of the form
pb.inheritIO()
behaves in exactly the same way as the invocation
pb.redirectInput(Redirect.INHERIT) .redirectOutput(Redirect.INHERIT) .redirectError(Redirect.INHERIT)
What I've tried to do is redirect System.out
(via System.setOut()
), and then create the process:
private static Process start(PrintStream out, Server server, String version) {
try {
System.setOut(out);
return new ProcessBuilder("java", "-jar", version + ".jar").inheritIO().directory(server.getDirectory()).start();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
If you are unfamilair with a Minecraft server structure, it looks a bit like this:
root/
├--plugins/ (if using Bukkit, as in my case)
├-- PluginName/
└-- PluginName.jar
└-- minecraft-server.jar (or some version of craftbukkit, in my case)
I typically have more than one version of the server software within the server's root directory, in case I need to use a specific version. (That's my reasoning behind the variables in the method)
The Process runs fine; I can see the output. But the output is in the wrong place. It's almost as if my System.setOut()
call was ignored, because I still see the output in the console, rather than in the GUI textbox. If I do a System.out.println
call, it outputs as I expect it to: on the GUI. So I am unsure how the 'inheriting' of the IO streams work.
Is there a way to listen/redirect/pipe it so I can print it to the GUI?