3/21/2023 0 Comments Ssh specify sidplay![]() OutputStream out = channel.getOutputStream() Ī more advanced solution would be to implement an Expect-like functionality. You may need to wait before sending the password. If I understand your question correctly, it looks like the password is provided too quickly and the way the server is implemented, it discards the input that comes too early (before a prompt). Providing input/subcommands to command executed over SSH with JSch Provide inputs to individual prompts separately with JSch You can also provide the input in your Java code rather than using shell constructs: See also Pipe multiple commands into a single command. Provide multiple lines of input to command executed on SSH server with JSchīash syntax for providing two lines of an input to a command is: ( echo input1 & echo input2 ) | command While ((line = reader.readLine()) != null) Or keep your command output stream reading code from your original question (you do not have to pass the output anywhere): InputStream in = channelExec.getInputStream() īufferedReader reader = new BufferedReader(new InputStreamReader(in)) Wait for the channel to be closed, before you close the session: while (!channelExec.isClosed()) Thread.sleep(100) So it's quite possible that the connection is simply terminated before the commands finishes, killing the command with it. "it doesn't work" is not a problem description.Īnyway, one obvious problem is, that you have removed the code that reads the command output and you have not replaced it with other way to wait for the command to finish. You didn't provide us any information, that we can use to debug your problem. Providing input/subcommands to command executed over SSH with JSch Using JSF Commands usually have command-line arguments/switches that serve the desired purpose better.Ī related question: Provide inputs to individual prompts separately with JSch. In general, it's always better to check if the command has better "API" than feeding the commands to input. OutputStream out = channelExec.getOutputStream() Something like this: ChannelExec channel = (ChannelExec) session.openChannel("exec") ĬtCommand("copy run tftp : ") If that's the case, you need to write them to the command input. Providing input/subcommands to command executed over SSH with JSchĬalling tCommand multiple times has no effect.Īnd even if it had, I'd guess that the 192.168.50.1 : and Config.txt are not commands, but inputs to the copy run tftp : command, aren't they?
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |