execChannel shouldn't allocate PTY

This commit is contained in:
Adrian Cole 2012-03-10 10:15:44 -08:00
parent aa14bf583c
commit 06ab36ae76
4 changed files with 32 additions and 9 deletions

View File

@ -491,7 +491,6 @@ public class JschSshClient implements SshClient {
checkConnected(); checkConnected();
String channel = "exec"; String channel = "exec";
executor = (ChannelExec) session.openChannel(channel); executor = (ChannelExec) session.openChannel(channel);
executor.setPty(true);
executor.setCommand(command); executor.setCommand(command);
ByteArrayOutputStream error = new ByteArrayOutputStream(); ByteArrayOutputStream error = new ByteArrayOutputStream();
executor.setErrStream(error); executor.setErrStream(error);

View File

@ -170,7 +170,7 @@ public class JschSshClientLiveTest {
: sshHost); : sshHost);
} }
public void testExecChannelTakesStdinAndEchosBack() throws IOException { public void testExecChannelTakesStdinAndNoEchoOfCharsInOuput() throws IOException {
ExecChannel response = setupClient().execChannel("cat <<EOF"); ExecChannel response = setupClient().execChannel("cat <<EOF");
assertEquals(response.getExitStatus().get(), null); assertEquals(response.getExitStatus().get(), null);
try { try {
@ -179,12 +179,10 @@ public class JschSshClientLiveTest {
printStream.append("EOF\n"); printStream.append("EOF\n");
printStream.close(); printStream.close();
assertEquals(Strings2.toStringAndClose(response.getError()), ""); assertEquals(Strings2.toStringAndClose(response.getError()), "");
// local echo assertEquals(Strings2.toStringAndClose(response.getOutput()), "");
assertEquals(Strings2.toStringAndClose(response.getOutput()), "foo\r\nEOF\r\n");
} finally { } finally {
Closeables.closeQuietly(response); Closeables.closeQuietly(response);
} }
assertEquals(response.getExitStatus().get(), new Integer(0)); assertEquals(response.getExitStatus().get(), new Integer(0));
} }
} }

View File

@ -504,6 +504,33 @@ public class SshjSshClient implements SshClient {
return acquire(new ExecConnection(command)); return acquire(new ExecConnection(command));
} }
protected Connection<Session> noPTYConnection() {
return new Connection<Session>() {
private Session session = null;
@Override
public void clear() throws TransportException, ConnectionException {
if (session != null)
session.close();
}
@Override
public Session create() throws Exception {
checkConnected();
session = ssh.startSession();
return session;
}
@Override
public String toString() {
return "Session()";
}
};
}
class ExecChannelConnection implements Connection<ExecChannel> { class ExecChannelConnection implements Connection<ExecChannel> {
private final String command; private final String command;
private SessionChannel session; private SessionChannel session;
@ -521,7 +548,7 @@ public class SshjSshClient implements SshClient {
@Override @Override
public ExecChannel create() throws Exception { public ExecChannel create() throws Exception {
session = SessionChannel.class.cast(acquire(execConnection())); session = SessionChannel.class.cast(acquire(noPTYConnection()));
output = session.exec(command); output = session.exec(command);
return new ExecChannel(output.getOutputStream(), output.getInputStream(), output.getErrorStream(), return new ExecChannel(output.getOutputStream(), output.getInputStream(), output.getErrorStream(),
new Supplier<Integer>() { new Supplier<Integer>() {

View File

@ -170,7 +170,7 @@ public class SshjSshClientLiveTest {
: sshHost); : sshHost);
} }
public void testExecChannelTakesStdinAndEchosBack() throws IOException { public void testExecChannelTakesStdinAndNoEchoOfCharsInOuput() throws IOException {
ExecChannel response = setupClient().execChannel("cat <<EOF"); ExecChannel response = setupClient().execChannel("cat <<EOF");
assertEquals(response.getExitStatus().get(), null); assertEquals(response.getExitStatus().get(), null);
try { try {
@ -179,8 +179,7 @@ public class SshjSshClientLiveTest {
printStream.append("EOF\n"); printStream.append("EOF\n");
printStream.close(); printStream.close();
assertEquals(Strings2.toStringAndClose(response.getError()), ""); assertEquals(Strings2.toStringAndClose(response.getError()), "");
// local echo assertEquals(Strings2.toStringAndClose(response.getOutput()), "");
assertEquals(Strings2.toStringAndClose(response.getOutput()), "foo\r\nEOF\r\n");
} finally { } finally {
Closeables.closeQuietly(response); Closeables.closeQuietly(response);
} }