I need to execute a command, and then enter a string of characters into the console, the console receives and prints it out, and then I try to get the content it prints, but it keeps blocking and the method cannot be executed.
Script executed,cmd.sh
read msg
echo $msg >>log.txt
echo $msg
Java code
DefaultTerminal build = DefaultTerminal.builder()
.host(host)
.port(port)
.password(password)
.username(username)
.build();
// ShellResult shellResult = SSH2ClientUtil.writeExec(cmd,() ->"777",build);
// This is the connection pool I encapsulated, the client I got here must be available
SSHClient client = SSH2ClientUtil.getClient(build);
Session.Command exec = client.startSession().exec(cmd);
OutputStream outputStream = exec.getOutputStream();
InputStream inputStream = exec.getInputStream();
// Write scripts are not executed, these are normal
exec.getOutputStream().write("ohhhh".getBytes(StandardCharsets.UTF_8));
outputStream.flush();
System.out.println("result++++"+new String(inputStream.readAllBytes(), StandardCharsets.UTF_8.toString()));
question from:
https://stackoverflow.com/questions/65917744/sshj-when-executing-instructions-that-need-to-be-input-reading-inputstream-afte 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…