I've been trying to run a batch file (run.bat for a minecraft server) via Java console. while i did manage to figure out a way to run the batch script on java, it seems that i cannot send commands from the console. the image below is the problem, typing help will not execute a command, is there a way to this?
I'm not allowed to embed images yet so here:
Here's my code snippet:
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException{
String line;
Process p = Runtime.getRuntime().exec("run.bat");
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null) {
System.out.println(line);
}
input.close();
}
}
new ProcessBuilder("cmd.exe", "/c", "\\foo\\bar\\run.bat").inheritIO().start();run.batprocess. You're not connecting your Java console's input to therun.batprocess's input.