These Linux commands are not support by console.command()
Edilmar
edilista at intersite.com.br
Tue Nov 8 09:32:08 MET 2005
maf at appgate.com wrote:
> On 31 okt, Edilmar wrote:
>
>>I'm using MindTerm 2.4.2 + JDK 1.5.0.
>>Commands not supported by console.command():
>>- su
>>=> standard in must be a tty
>>- more: it doesn't stop messages by page when using console.command()
>>within a terminal.
>
>
> Well, you could try telling the console to create a pty. For
> SSH2ConsoleRemote it is an argument and for SSH2Console you implement
> wantPTY (see examples/SSH1Example.java).
>
> /MaF
Hi,
I put "true" when calling command() but the cursor becomes freezed, no
chance to type a password for "su"... the sample code
RunRemoteCommand.java from MindTerm occurs the same problem. The message
"Password:" is displayed in RunRemoteCommand, but none occurs after
this. I put the command "su;ls", to run "su" and after "ls". The ";"
sintax works fine with other group of commands. I need to make work
mainly "su", to start scripts in the server, this is very important for
my application.
Below is the code of my app:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Properties;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;
import java.net.Socket;
import com.mindbright.ssh2.*;
import com.mindbright.terminal.*;
import com.mindbright.jca.security.SecureRandom;
import com.mindbright.util.SecureRandomAndPad;
import com.mindbright.util.RandomSeed;
import SubMacroForms.JPrincTab;
import SubMacroForms.GeralForms;
public class jinternalssh extends JFrame implements
TerminalMenuListener, Runnable {
private TerminalWin terminal;
private SSH2Transport transport;
private SSH2SimpleClient client;
private SSH2ConsoleRemote console;
private Properties props;
private LineReaderTerminal lineReader;
private int port, exitStatus;
private String host, user, passwd, title, cmdLine;
public jinternalssh(JPrincTab princtab, String host, String user,
String passwd, String cmdLine) {
setIconImage(princtab.getIconImage());
title = "Host: " + host + " - Usuario: " + user;
this.setTitle(title);
this.exitStatus = 1;
this.host = host;
this.user = user;
this.passwd = passwd;
this.port = 22;
this.cmdLine = cmdLine;
}
public void run() {
try {
props = new Properties();
terminal = new TerminalWin(this, new TerminalXTerm(), props);
RandomSeed seed = new RandomSeed();
seed.addEntropyGenerator(terminal);
setLayout(new BorderLayout());
add(terminal.getPanelWithScrollbar(), BorderLayout.CENTER);
TerminalFrameTitle frameTitle = new TerminalFrameTitle(this, title);
frameTitle.attach(terminal);
TerminalMenuHandler tmenus = null;
terminal.setClipboard(GlobalClipboard.getClipboardHandler());
pack();
show();
lineReader = new LineReaderTerminal(terminal);
terminal.write("jssh - Aplicacao Cliente de SSH - carregando
terminal...\n\r");
terminal.write(title + "\n\r");
terminal.write("========================================================\n\r\n\r");
SSH2Preferences prefs = new SSH2Preferences(props);
// It is important that the random number generator here is good!
SecureRandomAndPad secureRandom = new SecureRandomAndPad(
new SecureRandom(seed.getBytesBlocking(20, false)));
/*
* Open the TCP connection to the server and create the
* SSH2Transort object. No traffic will be sent yet.
*/
transport = new SSH2Transport(new Socket(host, port), prefs,
secureRandom);
/*
* Prepare for host fingerprint verification.
* This implementation check fingerprints agains properties of
* the form: fingerprint.HOSTNAME.PORT
*/
String fingerprint = props.getProperty("fingerprint." + host +
"." + port);
/*
* If we found a fingerprint property for this host:port then
* create a key verifier which checks that the fingerprint of the
* actual host matches.
*/
if(fingerprint != null) {
transport.setEventHandler(new SSH2HostKeyVerifier(fingerprint));
}
client = new SSH2SimpleClient(transport, user, passwd);
// This class will not interact with the user anymore.
lineReader.detach();
/*
* Create the remote console to use for command execution.
*/
if (cmdLine == null)
console = new SSH2ConsoleRemote(client.getConnection());
else {
console = new SSH2ConsoleRemote(client.getConnection(), null,
System.err);
console.command(cmdLine, true);
BufferedReader stdout = new BufferedReader(new
InputStreamReader(console.getStdOut()));
String line;
while((line = stdout.readLine()) != null) {
terminal.write(line + "\n\r");
}
}
SSH2TerminalAdapterImpl termAdapter = new
SSH2TerminalAdapterImpl(terminal);
if(!console.terminal(termAdapter)) {
throw new Exception("Nao foi possivel abrir terminal!");
}
exitStatus = console.waitForExitStatus();
} catch (LineReaderTerminal.ExternalMessageException e) {
// ignore
} catch (Exception e) {
GeralForms.showMessage(this, "Erro ocorrido: " + e.getMessage());
} finally {
dispose();
}
}
public void windowClosing(WindowEvent e) {
doClose();
}
public void close(TerminalMenuHandler originMenu) {
doClose();
}
public void doClose() {
if(lineReader != null) {
lineReader.breakPromptLine("");
}
if(console != null) {
console.close();
}
if(transport != null) {
transport.normalDisconnect("Usuario desconectado.");
}
}
public void update() {
}
}
!DSPAM:436f9da5100681920430396!
More information about the Mindterm-users
mailing list