I have a program that runs another Java program and sends commands to the program but it doesnt detect the commands. The program I am sending to the commands to uses JLine so I think that is the problem, it works for other programs that dont use it. This is the code I use to send the commands
// On process build
OutputStream stdin = process.getOutputStream();
DataOutputStream dataOutputStream = new DataOutputStream(stdin);
// On button click from javafx
dataOutputStream.write(command.getBytes());
dataOutputStream.flush();
I tried DataOutputStream and OutputStream.
The command just doesnt do anything, nothing happens. No output like invalid command message or anything. Reading the output does work and so do errors
I am not able to edit the code of the program I am trying to run
My full code if it helps https://github.com/JustDoom/JustDoomLauncher/blob/master/src/main/java/com/imjustdoom/doomlauncher/justdoomlauncher/process/GameProcess.java#L36 - Process is created and reading the process is handled https://github.com/JustDoom/JustDoomLauncher/blob/50b88bb658eb115f03fd3a9bf827c69147345e45/src/main/java/com/imjustdoom/doomlauncher/justdoomlauncher/application/ConsoleApplication.java#L42 - create custom console in javafx and write to the process
I fixed it. I ended up needing to add a newline to the writer before flushing. so I have this now.
dataOutputStream.write(command.getBytes());
dataOutputStream.write("\n".getBytes());
dataOutputStream.flush();
EDIT: The current answer does work but only in what seems like later versions and not older versions for jline