Use JSch sudo example and Channel.setPty for running sudo command on remote host

后端 未结 3 1992
再見小時候
再見小時候 2020-12-01 17:54

I have used JSch Sudo example under following link:

http://www.jcraft.com/jsch/examples/Sudo.java.html

And changed it a bit and get rid of all the dialogs as

3条回答
  •  春和景丽
    2020-12-01 18:20

    I have similar code in a project I am working on, and was getting the same error. I resolved this using the setPty(true) as you did.

    I think you're getting this error because you don't close out the streams in your code. If you are using Java 1.7, you can use a resource block as follows:

    try( InputStream in=channel.getInputStream() ) {
        try( OutputStream out = channel.getOutputStream() ) {
        ...
        }
    }
    

    or the try...finally block pattern from past versions.

提交回复
热议问题