mirror of https://github.com/apache/jclouds.git
execChannel shouldn't allocate PTY
This commit is contained in:
parent
aa14bf583c
commit
06ab36ae76
|
@ -491,7 +491,6 @@ public class JschSshClient implements SshClient {
|
|||
checkConnected();
|
||||
String channel = "exec";
|
||||
executor = (ChannelExec) session.openChannel(channel);
|
||||
executor.setPty(true);
|
||||
executor.setCommand(command);
|
||||
ByteArrayOutputStream error = new ByteArrayOutputStream();
|
||||
executor.setErrStream(error);
|
||||
|
|
|
@ -170,7 +170,7 @@ public class JschSshClientLiveTest {
|
|||
: sshHost);
|
||||
}
|
||||
|
||||
public void testExecChannelTakesStdinAndEchosBack() throws IOException {
|
||||
public void testExecChannelTakesStdinAndNoEchoOfCharsInOuput() throws IOException {
|
||||
ExecChannel response = setupClient().execChannel("cat <<EOF");
|
||||
assertEquals(response.getExitStatus().get(), null);
|
||||
try {
|
||||
|
@ -179,12 +179,10 @@ public class JschSshClientLiveTest {
|
|||
printStream.append("EOF\n");
|
||||
printStream.close();
|
||||
assertEquals(Strings2.toStringAndClose(response.getError()), "");
|
||||
// local echo
|
||||
assertEquals(Strings2.toStringAndClose(response.getOutput()), "foo\r\nEOF\r\n");
|
||||
assertEquals(Strings2.toStringAndClose(response.getOutput()), "");
|
||||
} finally {
|
||||
Closeables.closeQuietly(response);
|
||||
}
|
||||
assertEquals(response.getExitStatus().get(), new Integer(0));
|
||||
}
|
||||
|
||||
}
|
|
@ -504,6 +504,33 @@ public class SshjSshClient implements SshClient {
|
|||
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> {
|
||||
private final String command;
|
||||
private SessionChannel session;
|
||||
|
@ -521,7 +548,7 @@ public class SshjSshClient implements SshClient {
|
|||
|
||||
@Override
|
||||
public ExecChannel create() throws Exception {
|
||||
session = SessionChannel.class.cast(acquire(execConnection()));
|
||||
session = SessionChannel.class.cast(acquire(noPTYConnection()));
|
||||
output = session.exec(command);
|
||||
return new ExecChannel(output.getOutputStream(), output.getInputStream(), output.getErrorStream(),
|
||||
new Supplier<Integer>() {
|
||||
|
|
|
@ -170,7 +170,7 @@ public class SshjSshClientLiveTest {
|
|||
: sshHost);
|
||||
}
|
||||
|
||||
public void testExecChannelTakesStdinAndEchosBack() throws IOException {
|
||||
public void testExecChannelTakesStdinAndNoEchoOfCharsInOuput() throws IOException {
|
||||
ExecChannel response = setupClient().execChannel("cat <<EOF");
|
||||
assertEquals(response.getExitStatus().get(), null);
|
||||
try {
|
||||
|
@ -179,8 +179,7 @@ public class SshjSshClientLiveTest {
|
|||
printStream.append("EOF\n");
|
||||
printStream.close();
|
||||
assertEquals(Strings2.toStringAndClose(response.getError()), "");
|
||||
// local echo
|
||||
assertEquals(Strings2.toStringAndClose(response.getOutput()), "foo\r\nEOF\r\n");
|
||||
assertEquals(Strings2.toStringAndClose(response.getOutput()), "");
|
||||
} finally {
|
||||
Closeables.closeQuietly(response);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue