[JSch-users] executing command on a remote machine
Status: Alpha
Brought to you by:
ymnk
From: <sai...@ya...> - 2004-05-10 23:46:20
|
Hello , Can any body help me how to execute a command on a remote mahcine by using "shell" mode but not "exec" mode.I tried but it didnt work. Channel channel=session.openChannel("shell"); _sshInfo.setChannel(channel); command = "cd " + currentDirectory + "; ls -la"; PipedOutputStream pout = new PipedOutputStream(); channel.setInputStream(new PipedInputStream(pout)); PipedInputStream pin = new PipedInputStream(); channel.setOutputStream(new PipedOutputStream(pin)); channel.connect(); pout.write(command.getBytes()); InputStream in = channel.getInputStream(); StringBuffer sb=new StringBuffer(); String s = null; int c=0; while (!channel.isEOF()) { c = in.read(); if (c != -1) sb.append((char) c); } s = sb.toString(); _console.writetobuf(s); } catch (Exception ex) { Messages.error("SSH connection error: " + ex.getMessage() + " " + res.getString("SEE_ERROR_LOG"), ex, true); return; } this is how i implemented .Can any body comment about it. thank you sai ________________________________________________________________________ Yahoo! India Matrimony: Find your partner online. http://yahoo.shaadi.com/india-matrimony/ |