开发者

How can I route the output of a console .jar to another .jar appkication(GUI)?

开发者 https://www.devze.com 2023-01-26 08:16 出处:网络
I have my minecraft_server.jar开发者_开发技巧 file as my source. I want to run that and take the output of it to my .jar application. How?Use Runtime.exec to start the process and use Process.getOutpu

I have my minecraft_server.jar开发者_开发技巧 file as my source. I want to run that and take the output of it to my .jar application. How?


Use Runtime.exec to start the process and use Process.getOutputStream on the returned process object to access the output of that process:

Process proc = Runtime.getRuntime().exec("java -jar minecraft_server.jar");
OutputStream out = proc.getOutputStream();
/* read output using out */


The simple solution is system dependent. For example if you are using a Linux / Unix shell:

java -jar minecraft_server.jar | java -jar my_app.jar

You could also modify your application so that it launched the "minecraft server" application as an external command and read its output. But it is probably not worth the effort. (Hint, @casablanca's answer leaves out a lot of tedious detail such as handling exceptions, dealing with the standard error stream, dealing with return codes, the pathname of the java command, etc)

0

精彩评论

暂无评论...
验证码 换一张
取 消