I am using Java ProcessBuilder in MATLAB to open an executable in the background. This executable does some automated tasks, then pauses, waiting for user to type in some text and press enter.
I am able to send "enter key" commands to the executable via ProcessBuilder, but I am unable to send text strings. Can someone help me in this? Here is my code so far that initiates the executable in the background:
% specify the executable to run
run_exe_file = {'my_executable_program.exe'};
% initialize the java ProcessBuilder, run the executable
processBuilder = java.lang.ProcessBuilder(run_exe_file);
myProcess = processBuilder.start();
% initialize the reader. notice the myProcess in myProcess.getInputStream
reader = ...
java.io.BufferedReader(...
java.io.InputStreamReader(...
myProcess.getInputStream() ...
) ...
);
% initialize the writer. notice the myProcess in myProcess.getOutputStream
writer = ...
java.io.BufferedWriter(...
java.io.OutputStreamWriter(...
myProcess.getOutputStream() ...
) ...
);
After running the code above, 'my_executable_program.exe' starts running in the background successfully. After the background program run some tasks, it waits for user input. If for example I want to send an "enter key" press to the program I type in MATLAB the following:
writer.newLine; writer.flush; reader.readLine;
Which successfully sends the enter key command. However if I want to send some text to the program, from my understanding I am supposed to use the following code:
writer.write("Here is some text I'm sending to the program"); writer.flush; reader.readLine;
However running the above code does not send the text string to the program in my testing. Can someone help me with what is the proper syntax to send the text?
Thank you