Executing sudo using SSH “exec” channel in JSch
问题 I am using file in which I passed below commands: hostname pwd pbrun su - fclaim whoami cd .. pwd Ad the Java code below: for (String command1 : commands) { Channel channel=session.openChannel("exec"); ((ChannelExec)channel).setCommand(command1); in=channel.getInputStream(); channel.connect(); byte[] tmp=new byte[1024]; while(true){ while(in.available()>0){ int i=in.read(tmp, 0, 1024); if(i<0) break; System.out.println(new String(tmp, 0, i)); } if(channel.isClosed()){ break; } } channel