I am making a java program that takes an input and puts it to another console (windows). The thing is, the other console is a Minecraft server that is in the middle of running. The console has a > and it is waiting for me to type in a command. If I type help in manually, for example, it will run the help command and return the output. Then it will remain with the > waiting for another command until it gets stopped. How can I write to this type of console from a Java process? I tried BufferedWriter, PrintWriter, and OutputStreamWriter. I've been making getting the output stream by running Process process = Runtime.getRuntime().exec("java -jar server.jar"); How can I write to this console? (Reading works fine)
            Asked
            
        
        
            Active
            
        
            Viewed 176 times
        
    1
            
            
        
        Konrad Rudolph
        
- 530,221
 - 131
 - 937
 - 1,214
 
        YHDiamond
        
- 134
 - 7
 
- 
                    You can send bytes to the minecraft server's input stream (the thing that gets populated when you physically type into the console). See https://stackoverflow.com/a/2563432/5601284 – byxor Feb 17 '21 at 18:31
 - 
                    You can't send things to input stream... You write to Outputstream... I also mentioned that I tried that and it did not work – YHDiamond Feb 17 '21 at 18:59
 - 
                    So use `getOutputStream()` and write data to it. The data you write is read as standard input by the server. Your description of what you've tried is vague – byxor Feb 17 '21 at 19:33
 - 
                    Trying Runtime.getRuntime().exec("commandblahblahblah").getOutputStream().write("stuf") did not work. – YHDiamond Feb 17 '21 at 19:50
 - 
                    You also need to flush the stream and close it https://www.rgagnon.com/javadetails/java-0014.html – byxor Feb 17 '21 at 21:19
 - 
                    If I close the stream I am unable to write more afterwards I will need to be able to send more commands after the first one. My program has an input section where you input commands, you see. – YHDiamond Feb 17 '21 at 23:52