I need to start jar and provide input to it. I've found how to start jar, which works without problems, using Runtime#getRuntime#exec, and I've also found that
String command = "stop";
BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(process.getOutputStream()));
bufferedWriter.write(String.format("%s\n", command));
bufferedWriter.flush();
should do the job. But the problem is, it just doesn't work for me, it literally does nothing. Does anyone know how to do that? Process:
public static Process startJar(File jarFile, String flags, String args, @Nullable File dir) throws IOException {
if (dir == null){
return Runtime.getRuntime().exec(String.format("cmd /c start /wait \"\" java -jar %s \"%s\" %s",flags ,jarFile.getAbsolutePath(), args));
}
return Runtime.getRuntime().exec(String.format("cmd /c start /wait \"\" java -jar %s \"%s\" %s", flags, jarFile.getAbsolutePath(), args), null, dir);
}